|
5 | 5 | import contextlib |
6 | 6 | import dataclasses |
7 | 7 | import re |
| 8 | +from collections.abc import Iterator, Mapping, Sequence |
8 | 9 | from functools import cached_property |
9 | | -from typing import ( |
10 | | - TYPE_CHECKING, |
11 | | - Any, |
12 | | - ClassVar, |
13 | | - Generic, |
14 | | - Iterator, |
15 | | - Mapping, |
16 | | - Sequence, |
17 | | - TypeVar, |
18 | | - overload, |
19 | | -) |
| 10 | +from typing import TYPE_CHECKING, Any, ClassVar, Generic, TypeVar, overload |
20 | 11 |
|
21 | 12 | from mkdocstrings.handlers.base import CollectionError |
22 | 13 |
|
23 | 14 | from . import crystal_html |
24 | 15 |
|
25 | 16 | if TYPE_CHECKING: |
| 17 | + from typing_extensions import Self |
| 18 | + |
26 | 19 | from .collector import DocRoot |
27 | 20 |
|
28 | 21 |
|
29 | | -class DocItem(metaclass=abc.ABCMeta): |
| 22 | +class DocItem(abc.ABC): |
30 | 23 | """A representation of a documentable item from Crystal language.""" |
31 | 24 |
|
32 | 25 | _TEMPLATE: str |
@@ -140,18 +133,16 @@ class DocType(DocItem): |
140 | 133 | _TEMPLATE = "type.html" |
141 | 134 |
|
142 | 135 | @overload |
143 | | - def __new__(cls: type[DocType], data: Mapping[str, Any], *args, **kwargs) -> DocType: |
144 | | - ... |
| 136 | + def __new__(cls, data: Mapping[str, Any], *args, **kwargs) -> Self: ... |
145 | 137 |
|
146 | 138 | @overload |
147 | | - def __new__(cls, data: Mapping[str, Any] | None = None, *args, **kwargs) -> DocType: |
148 | | - ... |
| 139 | + def __new__(cls, data: Mapping[str, Any] | None = None, *args, **kwargs) -> Self: ... |
149 | 140 |
|
150 | | - def __new__(cls, data=None, *args, **kwargs) -> DocType: |
| 141 | + def __new__(cls, data=None, *args, **kwargs) -> Self: |
151 | 142 | """Based on Crystal's JSON, create an object of an appropriate subclass of DocType""" |
152 | 143 | if cls is DocType: |
153 | 144 | try: |
154 | | - cls = _doc_type_mapping[data["kind"]] |
| 145 | + cls = _doc_type_mapping[data["kind"]] # type: ignore[assignment] |
155 | 146 | except KeyError: |
156 | 147 | raise TypeError( |
157 | 148 | "DocType is abstract, and {kind!r} is not recognized".format_map(data) |
@@ -431,10 +422,11 @@ class DocMapping(Generic[D]): |
431 | 422 | search: Mapping[str, Any] = {} |
432 | 423 | _empty: ClassVar[DocMapping] |
433 | 424 |
|
434 | | - def __new__(cls, items: Sequence[D]) -> DocMapping: |
| 425 | + def __new__(cls, items: Sequence[D]) -> Self: |
435 | 426 | if not items: |
| 427 | + empty: Self |
436 | 428 | try: |
437 | | - empty = cls._empty |
| 429 | + empty = cls._empty # type: ignore[assignment] |
438 | 430 | except AttributeError: |
439 | 431 | cls._empty = empty = object.__new__(cls) |
440 | 432 | return empty |
|
0 commit comments