Skip to content

Commit

Permalink
_typing_internal_name
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Apr 23, 2024
1 parent 364c342 commit 88271fd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sphinx/util/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _is_annotated_form(obj: Any) -> TypeGuard[Annotated[Any, ...]]:
return typing.get_origin(obj) is Annotated or str(obj).startswith('typing.Annotated')


def _get_typing_internal_name(obj: Any) -> str | None:
def _typing_internal_name(obj: Any) -> str | None:
if sys.version_info[:2] >= (3, 10):
return obj.__name__
return getattr(obj, '_name', None)
Expand Down Expand Up @@ -252,7 +252,7 @@ def restify(cls: Any, mode: _RestifyMode = 'fully-qualified-except-typing') -> s
# *cls* is defined in ``typing``, and thus ``__args__`` must exist
return ' | '.join(restify(a, mode) for a in cls.__args__)
elif inspect.isgenericalias(cls):
cls_name = _get_typing_internal_name(cls)
cls_name = _typing_internal_name(cls)

if isinstance(cls.__origin__, typing._SpecialForm):
# ClassVar; Concatenate; Final; Literal; Unpack; TypeGuard
Expand All @@ -272,14 +272,14 @@ def restify(cls: Any, mode: _RestifyMode = 'fully-qualified-except-typing') -> s

# Callable has special formatting
if (
(cls_module_is_typing and _get_typing_internal_name(cls) == 'Callable')
(cls_module_is_typing and _typing_internal_name(cls) == 'Callable')
or (cls.__module__ == 'collections.abc' and cls.__name__ == 'Callable')
):
args = ', '.join(restify(a, mode) for a in __args__[:-1])
returns = restify(__args__[-1], mode)
return fr'{text}\ [[{args}], {returns}]'

if cls_module_is_typing and _get_typing_internal_name(cls.__origin__) == 'Literal':
if cls_module_is_typing and _typing_internal_name(cls.__origin__) == 'Literal':
args = ', '.join(_format_literal_arg_restify(a, mode=mode)
for a in cls.__args__)
return fr'{text}\ [{args}]'
Expand All @@ -288,7 +288,7 @@ def restify(cls: Any, mode: _RestifyMode = 'fully-qualified-except-typing') -> s
args = ', '.join(restify(a, mode) for a in __args__)
return fr'{text}\ [{args}]'
elif isinstance(cls, typing._SpecialForm):
cls_name = _get_typing_internal_name(cls)
cls_name = _typing_internal_name(cls)
return f':py:obj:`~{cls.__module__}.{cls_name}`'
elif sys.version_info[:2] >= (3, 11) and cls is typing.Any:
# handle bpo-46998
Expand Down

0 comments on commit 88271fd

Please sign in to comment.