Skip to content

Commit 03c2373

Browse files
committed
Extract _is_typing() to module level
1 parent 68d5610 commit 03c2373

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

sphinx/domains/python/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
py_sig_re,
5353
)
5454

55+
_TYPING_ALL = frozenset(typing.__all__)
56+
5557
logger = logging.getLogger(__name__)
5658

5759
pairindextypes = {
@@ -1076,13 +1078,6 @@ def builtin_resolver(
10761078
app: Sphinx, env: BuildEnvironment, node: pending_xref, contnode: Element
10771079
) -> Element | None:
10781080
"""Do not emit nitpicky warnings for built-in types."""
1079-
1080-
def istyping(s: str) -> bool:
1081-
if s.startswith('typing.'):
1082-
s = s.split('.', 1)[1]
1083-
1084-
return s in typing.__all__
1085-
10861081
if node.get('refdomain') != 'py':
10871082
return None
10881083
elif node.get('reftype') in {'class', 'obj'} and node.get('reftarget') == 'None':
@@ -1092,13 +1087,17 @@ def istyping(s: str) -> bool:
10921087
if inspect.isclass(getattr(builtins, reftarget, None)):
10931088
# built-in class
10941089
return contnode
1095-
if istyping(reftarget):
1090+
if _is_typing(reftarget):
10961091
# typing class
10971092
return contnode
10981093

10991094
return None
11001095

11011096

1097+
def _is_typing(s: str, /) -> bool:
1098+
return s.removeprefix('typing.') in _TYPING_ALL
1099+
1100+
11021101
def setup(app: Sphinx) -> ExtensionMetadata:
11031102
app.setup_extension('sphinx.directives')
11041103

0 commit comments

Comments
 (0)