Skip to content

Commit d79206f

Browse files
committed
Make TypeVars private
1 parent 502e0c7 commit d79206f

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

mkdocstrings_handlers/crystal/collector.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
log = logging.getLogger(f"mkdocs.plugins.{__name__}")
2727

2828
if TYPE_CHECKING:
29-
D = TypeVar("D", bound=DocItem)
29+
_D = TypeVar("_D", bound=DocItem)
3030

3131

3232
class CrystalCollector(BaseHandler):
@@ -226,9 +226,9 @@ def _get_locations(cls, obj: DocItem) -> Sequence[str]:
226226
def _filter(
227227
cls,
228228
filters: Sequence[str] | bool, # noqa: FBT001
229-
mapp: DocMapping[D],
230-
getter: Callable[[D], Sequence[str]],
231-
) -> DocMapping[D]:
229+
mapp: DocMapping[_D],
230+
getter: Callable[[_D], Sequence[str]],
231+
) -> DocMapping[_D]:
232232
if filters is False:
233233
return DocMapping(())
234234
if filters is True:

mkdocstrings_handlers/crystal/crystal_html.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import html.parser
55
import io
66
from collections.abc import Iterable, Sequence
7-
from typing import Callable
7+
from typing import TYPE_CHECKING, Callable
88

99
from markupsafe import Markup, escape
1010

11-
LinkToken = tuple[int, int, str]
11+
if TYPE_CHECKING:
12+
_LinkToken = tuple[int, int, str]
1213

1314

1415
class TextWithLinks(collections.UserString):
@@ -19,10 +20,10 @@ class TextWithLinks(collections.UserString):
1920
The link information is currently for internal use only.
2021
"""
2122

22-
tokens: Sequence[LinkToken]
23+
tokens: Sequence[_LinkToken]
2324
"""The list of embedded links."""
2425

25-
def __init__(self, string, tokens: Sequence[LinkToken]):
26+
def __init__(self, string, tokens: Sequence[_LinkToken]):
2627
super().__init__(string)
2728
self.tokens = tokens
2829

@@ -37,7 +38,7 @@ def parse_crystal_html(crystal_html: str) -> TextWithLinks:
3738

3839

3940
def linkify_highlighted_html(
40-
pygments_html: str, html_tokens: Sequence[LinkToken], make_link: Callable[[str, str], str]
41+
pygments_html: str, html_tokens: Sequence[_LinkToken], make_link: Callable[[str, str], str]
4142
) -> str:
4243
pygments_parser = _PygmentsHTMLHandler(html_tokens, make_link)
4344
pygments_parser.feed(pygments_html)
@@ -48,7 +49,7 @@ class _CrystalHTMLHandler(html.parser.HTMLParser):
4849
def __init__(self) -> None:
4950
super().__init__()
5051
self.text = io.StringIO()
51-
self.tokens: list[LinkToken] = []
52+
self.tokens: list[_LinkToken] = []
5253
self._link_starts: list[tuple[int, str]] = []
5354

5455
def handle_starttag(self, tag, attrs):
@@ -73,7 +74,7 @@ def link_to_path(cls, href):
7374

7475

7576
class _PygmentsHTMLHandler(html.parser.HTMLParser):
76-
def __init__(self, tokens: Iterable[LinkToken], make_link: Callable[[str, str], str]):
77+
def __init__(self, tokens: Iterable[_LinkToken], make_link: Callable[[str, str], str]):
7778
super().__init__()
7879
self.tokens = iter(tokens)
7980
self.make_link = make_link

mkdocstrings_handlers/crystal/items.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def lookup(self, identifier: str | DocPath) -> DocItem:
124124
}
125125

126126

127-
D = TypeVar("D", bound=DocItem)
127+
_D = TypeVar("_D", bound=DocItem)
128128

129129

130130
class DocType(DocItem):
@@ -415,14 +415,14 @@ class DocConstructor(DocClassMethod):
415415
"""A [DocInstanceMethod][mkdocstrings_handlers.crystal.items.DocInstanceMethod] representing a Crystal macro."""
416416

417417

418-
class DocMapping(Generic[D]):
418+
class DocMapping(Generic[_D]):
419419
"""Represents items contained within a type. A container of [DocItem][mkdocstrings_handlers.crystal.items.DocItem]s."""
420420

421421
items: Sequence = ()
422422
search: Mapping[str, Any] = {}
423423
_empty: ClassVar[DocMapping]
424424

425-
def __new__(cls, items: Sequence[D]) -> Self:
425+
def __new__(cls, items: Sequence[_D]) -> Self:
426426
if not items:
427427
empty: Self
428428
try:
@@ -432,15 +432,15 @@ def __new__(cls, items: Sequence[D]) -> Self:
432432
return empty
433433
return object.__new__(cls)
434434

435-
def __init__(self, items: Sequence[D]):
435+
def __init__(self, items: Sequence[_D]):
436436
self.items = items
437437
search: dict[str, Any] = {}
438438
self.search = search
439439
for item in self.items:
440440
search.setdefault(item.rel_id, item)
441441
search.setdefault(item.name, item)
442442

443-
def __iter__(self) -> Iterator[D]:
443+
def __iter__(self) -> Iterator[_D]:
444444
"""Iterate over the items like a list."""
445445
return iter(self.items)
446446

@@ -456,7 +456,7 @@ def __contains__(self, key: str) -> bool:
456456
"""`"identifier" in mapping` to check whether the mapping contains an item by this identifier (see [DocItem.rel_id][mkdocstrings_handlers.crystal.items.DocItem.rel_id])."""
457457
return key in self.search
458458

459-
def __getitem__(self, key: str) -> D:
459+
def __getitem__(self, key: str) -> _D:
460460
"""`mapping["identifier"]` to get the item by this identifier (see [DocItem.rel_id][mkdocstrings_handlers.crystal.items.DocItem.rel_id]).
461461
462462
Returns:

mkdocstrings_handlers/crystal/renderer.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import contextlib
44
import xml.etree.ElementTree as etree
55
from collections.abc import Mapping
6-
from typing import TYPE_CHECKING, Any, TypeVar
6+
from typing import TYPE_CHECKING, Any
77

88
import jinja2
99
import markdown_callouts
@@ -18,8 +18,6 @@
1818

1919
from .items import DocItem, DocPath
2020

21-
T = TypeVar("T")
22-
2321

2422
class CrystalRenderer(base.BaseHandler):
2523
fallback_theme = "material"

0 commit comments

Comments
 (0)