Skip to content

Commit 6d91311

Browse files
committed
Remove typing_extensions
1 parent 0266507 commit 6d91311

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

sphinx/util/typing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ def _is_annotated_form(obj: Any) -> TypeGuard[Annotated[Any, ...]]:
180180

181181
def _is_unpack_form(obj: Any) -> bool:
182182
"""Check if the object is :class:`typing.Unpack` or equivalent."""
183+
if sys.version_info >= (3, 11):
184+
from typing import Unpack
185+
186+
return typing.get_origin(obj) is Unpack
183187
origin = typing.get_origin(obj)
184188
origin_module = getattr(origin, '__module__', None)
185189
origin_name = getattr(origin, '__name__', None)

tests/test_util/test_util_typing.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -325,25 +325,19 @@ def test_restify_pep_585():
325325
":py:class:`int`]")
326326

327327

328+
@pytest.mark.skipif(sys.version_info[:2] <= (3, 11), reason='python 3.11+ is required.')
328329
def test_restify_Unpack():
329-
import typing
330+
from typing import Unpack
330331

331-
from typing_extensions import Unpack as UnpackCompat
332-
333-
class X(typing.TypedDict):
332+
class X(t.TypedDict):
334333
x: int
335334
y: int
336335
label: str
337336

338337
# Unpack is considered as typing special form so we always have '~'
339-
expect = rf':py:obj:`~{UnpackCompat.__module__}.Unpack`\ [:py:class:`X`]'
340-
assert restify(UnpackCompat['X'], 'fully-qualified-except-typing') == expect
341-
assert restify(UnpackCompat['X'], 'smart') == expect
342-
343-
if NativeUnpack := getattr(typing, 'Unpack', None):
344-
expect = r':py:obj:`~typing.Unpack`\ [:py:class:`X`]'
345-
assert restify(NativeUnpack['X'], 'fully-qualified-except-typing') == expect
346-
assert restify(NativeUnpack['X'], 'smart') == expect
338+
expect = r':py:obj:`~typing.Unpack`\ [:py:class:`X`]'
339+
assert restify(Unpack['X'], 'fully-qualified-except-typing') == expect
340+
assert restify(Unpack['X'], 'smart') == expect
347341

348342

349343
@pytest.mark.skipif(sys.version_info[:2] <= (3, 9), reason='python 3.10+ is required.')
@@ -495,29 +489,17 @@ def test_stringify_Annotated():
495489
assert stringify_annotation(Annotated[str, "foo", "bar"], "smart") == "str"
496490

497491

492+
@pytest.mark.skipif(sys.version_info[:2] <= (3, 11), reason='python 3.11+ is required.')
498493
def test_stringify_Unpack():
499-
import typing
500-
501-
from typing_extensions import Unpack as UnpackCompat
494+
from typing import Unpack
502495

503-
class X(typing.TypedDict):
496+
class X(t.TypedDict):
504497
x: int
505498
y: int
506499
label: str
507500

508-
# typing.Unpack is introduced in 3.11 but typing_extensions.Unpack
509-
# is only using typing.Unpack since 3.12, so those objects are not
510-
# synchronized with each other.
511-
if hasattr(typing, 'Unpack') and typing.Unpack is UnpackCompat:
512-
assert stringify_annotation(UnpackCompat['X']) == 'Unpack[X]'
513-
assert stringify_annotation(UnpackCompat['X'], 'smart') == '~typing.Unpack[X]'
514-
else:
515-
assert stringify_annotation(UnpackCompat['X']) == 'typing_extensions.Unpack[X]'
516-
assert stringify_annotation(UnpackCompat['X'], 'smart') == '~typing_extensions.Unpack[X]'
517-
518-
if NativeUnpack := getattr(typing, 'Unpack', None):
519-
assert stringify_annotation(NativeUnpack['X']) == 'Unpack[X]'
520-
assert stringify_annotation(NativeUnpack['X'], 'smart') == '~typing.Unpack[X]'
501+
assert stringify_annotation(Unpack['X']) == 'Unpack[X]'
502+
assert stringify_annotation(Unpack['X'], 'smart') == '~typing.Unpack[X]'
521503

522504

523505
def test_stringify_type_hints_string():

0 commit comments

Comments
 (0)