1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Date: Sun, 16 Feb 2025 23:39:46 +0100
Subject: Replace old typing_extensions imports in tests
Origin: upstream, https://github.com/python/mypy/pull/18691
Bug-Debian: https://bugs.debian.org/1101856
Last-Update: 2025-04-07
---
mypy/test/teststubtest.py | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py
index f3199da..101b6f6 100644
--- a/mypy/test/teststubtest.py
+++ b/mypy/test/teststubtest.py
@@ -48,6 +48,11 @@ Callable: _SpecialForm = ...
Generic: _SpecialForm = ...
Protocol: _SpecialForm = ...
Union: _SpecialForm = ...
+ClassVar: _SpecialForm = ...
+
+Final = 0
+Literal = 0
+TypedDict = 0
class TypeVar:
def __init__(self, name, covariant: bool = ..., contravariant: bool = ...) -> None: ...
@@ -71,6 +76,12 @@ class Match(Generic[AnyStr]): ...
class Sequence(Iterable[_T_co]): ...
class Tuple(Sequence[_T_co]): ...
class NamedTuple(tuple[Any, ...]): ...
+class _TypedDict(Mapping[str, object]):
+ __required_keys__: ClassVar[frozenset[str]]
+ __optional_keys__: ClassVar[frozenset[str]]
+ __total__: ClassVar[bool]
+ __readonly_keys__: ClassVar[frozenset[str]]
+ __mutable_keys__: ClassVar[frozenset[str]]
def overload(func: _T) -> _T: ...
def type_check_only(func: _T) -> _T: ...
def final(func: _T) -> _T: ...
@@ -95,6 +106,8 @@ class tuple(Sequence[T_co], Generic[T_co]):
class dict(Mapping[KT, VT]): ...
+class frozenset(Generic[T]): ...
+
class function: pass
class ellipsis: pass
@@ -1373,7 +1386,7 @@ class StubtestUnit(unittest.TestCase):
)
yield Case(
stub="""
- from typing_extensions import Final, Literal
+ from typing import Final, Literal
class BytesEnum(bytes, enum.Enum):
a = b'foo'
FOO: Literal[BytesEnum.a]
@@ -1915,7 +1928,7 @@ assert annotations
def test_good_literal(self) -> Iterator[Case]:
yield Case(
stub=r"""
- from typing_extensions import Literal
+ from typing import Literal
import enum
class Color(enum.Enum):
@@ -1947,7 +1960,7 @@ assert annotations
@collect_cases
def test_bad_literal(self) -> Iterator[Case]:
- yield Case("from typing_extensions import Literal", "", None) # dummy case
+ yield Case("from typing import Literal", "", None) # dummy case
yield Case(
stub="INT_FLOAT_MISMATCH: Literal[1]",
runtime="INT_FLOAT_MISMATCH = 1.0",
@@ -1998,7 +2011,7 @@ assert annotations
)
yield Case(
stub="""
- from typing_extensions import TypedDict
+ from typing import TypedDict
class _Options(TypedDict):
a: str
@@ -2019,8 +2032,8 @@ assert annotations
@collect_cases
def test_runtime_typing_objects(self) -> Iterator[Case]:
yield Case(
- stub="from typing_extensions import Protocol, TypedDict",
- runtime="from typing_extensions import Protocol, TypedDict",
+ stub="from typing import Protocol, TypedDict",
+ runtime="from typing import Protocol, TypedDict",
error=None,
)
yield Case(
@@ -2385,8 +2398,8 @@ assert annotations
)
# The same is true for NamedTuples and TypedDicts:
yield Case(
- stub="from typing_extensions import NamedTuple, TypedDict",
- runtime="from typing_extensions import NamedTuple, TypedDict",
+ stub="from typing import NamedTuple, TypedDict",
+ runtime="from typing import NamedTuple, TypedDict",
error=None,
)
yield Case(
|