parent
b5335b825d
commit
623dffad7e
@ -1,276 +0,0 @@
|
||||
From 1913db5ae20e95e636471cc79208330dfe7a1d72 Mon Sep 17 00:00:00 2001
|
||||
From: Noel Evans <noelevans@gmail.com>
|
||||
Date: Wed, 25 Nov 2020 22:09:44 +0000
|
||||
Subject: [PATCH 1/3] Fix tests failing with 3.10.0a2+
|
||||
|
||||
---
|
||||
.../src_py3/test_typing_extensions.py | 39 ++++++++++++++++---
|
||||
1 file changed, 33 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/typing_extensions/src_py3/test_typing_extensions.py b/typing_extensions/src_py3/test_typing_extensions.py
|
||||
index 0222303..89c3037 100644
|
||||
--- a/typing_extensions/src_py3/test_typing_extensions.py
|
||||
+++ b/typing_extensions/src_py3/test_typing_extensions.py
|
||||
@@ -9,7 +9,7 @@
|
||||
from unittest import TestCase, main, skipUnless, skipIf
|
||||
from typing import TypeVar, Optional
|
||||
from typing import T, KT, VT # Not in __all__.
|
||||
-from typing import Tuple, List, Dict, Iterator
|
||||
+from typing import ForwardRef, Tuple, List, Dict, Iterator
|
||||
from typing import Generic
|
||||
from typing import no_type_check
|
||||
from typing_extensions import NoReturn, ClassVar, Final, IntVar, Literal, Type, NewType, TypedDict
|
||||
@@ -71,6 +71,9 @@
|
||||
# For checks reliant on Python 3.6 syntax changes (e.g. classvar)
|
||||
PY36 = sys.version_info[:2] >= (3, 6)
|
||||
|
||||
+# For checks reliant on Python 3.10
|
||||
+PY3_10 = sys.version_info[:2] >= (3, 10)
|
||||
+
|
||||
# Protocols are hard to backport to the original version of typing 3.5.0
|
||||
HAVE_PROTOCOLS = sys.version_info[:3] != (3, 5, 0)
|
||||
|
||||
@@ -1516,7 +1519,6 @@ def test_typeddict_errors(self):
|
||||
def test_py36_class_syntax_usage(self):
|
||||
self.assertEqual(LabelPoint2D.__name__, 'LabelPoint2D')
|
||||
self.assertEqual(LabelPoint2D.__module__, __name__)
|
||||
- self.assertEqual(LabelPoint2D.__annotations__, {'x': int, 'y': int, 'label': str})
|
||||
self.assertEqual(LabelPoint2D.__bases__, (dict,))
|
||||
self.assertEqual(LabelPoint2D.__total__, True)
|
||||
self.assertNotIsSubclass(LabelPoint2D, typing.Sequence)
|
||||
@@ -1525,6 +1527,13 @@ def test_py36_class_syntax_usage(self):
|
||||
self.assertEqual(not_origin['y'], 1)
|
||||
other = LabelPoint2D(x=0, y=1, label='hi')
|
||||
self.assertEqual(other['label'], 'hi')
|
||||
+ if PY3_10:
|
||||
+ self.assertEqual(LabelPoint2D.__annotations__, {
|
||||
+ 'x': ForwardRef('int'),
|
||||
+ 'y': ForwardRef('int'),
|
||||
+ 'label': str})
|
||||
+ else:
|
||||
+ self.assertEqual(LabelPoint2D.__annotations__, {'x': int, 'y': int, 'label': str})
|
||||
|
||||
def test_pickle(self):
|
||||
global EmpD # pickle wants to reference the class by name
|
||||
@@ -1565,18 +1574,21 @@ def test_optional_keys(self):
|
||||
def test_keys_inheritance(self):
|
||||
assert BaseAnimal.__required_keys__ == frozenset(['name'])
|
||||
assert BaseAnimal.__optional_keys__ == frozenset([])
|
||||
- assert BaseAnimal.__annotations__ == {'name': str}
|
||||
|
||||
assert Animal.__required_keys__ == frozenset(['name'])
|
||||
assert Animal.__optional_keys__ == frozenset(['tail', 'voice'])
|
||||
+
|
||||
+ assert Cat.__required_keys__ == frozenset(['name', 'fur_color'])
|
||||
+ assert Cat.__optional_keys__ == frozenset(['tail', 'voice'])
|
||||
+
|
||||
+ @skipUnless(PY36 and not PY3_10, 'Python 3.6 and < 3.10 required')
|
||||
+ def test_keys_inheritance_before_postponed_annotation_eval(self):
|
||||
+ assert BaseAnimal.__annotations__ == {'name': str}
|
||||
assert Animal.__annotations__ == {
|
||||
'name': str,
|
||||
'tail': bool,
|
||||
'voice': str,
|
||||
}
|
||||
-
|
||||
- assert Cat.__required_keys__ == frozenset(['name', 'fur_color'])
|
||||
- assert Cat.__optional_keys__ == frozenset(['tail', 'voice'])
|
||||
assert Cat.__annotations__ == {
|
||||
'fur_color': str,
|
||||
'name': str,
|
||||
@@ -1584,6 +1596,21 @@ def test_keys_inheritance(self):
|
||||
'voice': str,
|
||||
}
|
||||
|
||||
+ @skipUnless(PY3_10, 'Python 3.10 required')
|
||||
+ def test_keys_inheritance_with_postponed_annotation_eval(self):
|
||||
+ assert BaseAnimal.__annotations__ == {'name': ForwardRef('str')}
|
||||
+ assert Animal.__annotations__ == {
|
||||
+ 'name': ForwardRef('str'),
|
||||
+ 'tail': ForwardRef('bool'),
|
||||
+ 'voice': ForwardRef('str'),
|
||||
+ }
|
||||
+ assert Cat.__annotations__ == {
|
||||
+ 'fur_color': ForwardRef('str'),
|
||||
+ 'name': ForwardRef('str'),
|
||||
+ 'tail': ForwardRef('bool'),
|
||||
+ 'voice': ForwardRef('str'),
|
||||
+ }
|
||||
+
|
||||
|
||||
@skipUnless(TYPING_3_5_3, "Python >= 3.5.3 required")
|
||||
class AnnotatedTests(BaseTestCase):
|
||||
|
||||
From a6b50a9788cb071ff11c408a7212bef1bad9b233 Mon Sep 17 00:00:00 2001
|
||||
From: Noel Evans <noelevans@gmail.com>
|
||||
Date: Wed, 25 Nov 2020 22:34:12 +0000
|
||||
Subject: [PATCH 2/3] Fix import issue
|
||||
|
||||
---
|
||||
.../src_py3/test_typing_extensions.py | 24 +++++++++----------
|
||||
1 file changed, 12 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/typing_extensions/src_py3/test_typing_extensions.py b/typing_extensions/src_py3/test_typing_extensions.py
|
||||
index 89c3037..1c02877 100644
|
||||
--- a/typing_extensions/src_py3/test_typing_extensions.py
|
||||
+++ b/typing_extensions/src_py3/test_typing_extensions.py
|
||||
@@ -9,7 +9,7 @@
|
||||
from unittest import TestCase, main, skipUnless, skipIf
|
||||
from typing import TypeVar, Optional
|
||||
from typing import T, KT, VT # Not in __all__.
|
||||
-from typing import ForwardRef, Tuple, List, Dict, Iterator
|
||||
+from typing import Tuple, List, Dict, Iterator
|
||||
from typing import Generic
|
||||
from typing import no_type_check
|
||||
from typing_extensions import NoReturn, ClassVar, Final, IntVar, Literal, Type, NewType, TypedDict
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
OLD_GENERICS = False
|
||||
try:
|
||||
- from typing import _type_vars, _next_in_mro, _type_check # noqa
|
||||
+ from typing import _type_vars, _next_in_mro, _type_check # noqa
|
||||
except ImportError:
|
||||
OLD_GENERICS = True
|
||||
|
||||
@@ -1529,8 +1529,8 @@ def test_py36_class_syntax_usage(self):
|
||||
self.assertEqual(other['label'], 'hi')
|
||||
if PY3_10:
|
||||
self.assertEqual(LabelPoint2D.__annotations__, {
|
||||
- 'x': ForwardRef('int'),
|
||||
- 'y': ForwardRef('int'),
|
||||
+ 'x': typing.ForwardRef('int'),
|
||||
+ 'y': typing.ForwardRef('int'),
|
||||
'label': str})
|
||||
else:
|
||||
self.assertEqual(LabelPoint2D.__annotations__, {'x': int, 'y': int, 'label': str})
|
||||
@@ -1598,17 +1598,17 @@ def test_keys_inheritance_before_postponed_annotation_eval(self):
|
||||
|
||||
@skipUnless(PY3_10, 'Python 3.10 required')
|
||||
def test_keys_inheritance_with_postponed_annotation_eval(self):
|
||||
- assert BaseAnimal.__annotations__ == {'name': ForwardRef('str')}
|
||||
+ assert BaseAnimal.__annotations__ == {'name': typing.ForwardRef('str')}
|
||||
assert Animal.__annotations__ == {
|
||||
- 'name': ForwardRef('str'),
|
||||
- 'tail': ForwardRef('bool'),
|
||||
- 'voice': ForwardRef('str'),
|
||||
+ 'name': typing.ForwardRef('str'),
|
||||
+ 'tail': typing.ForwardRef('bool'),
|
||||
+ 'voice': typing.ForwardRef('str'),
|
||||
}
|
||||
assert Cat.__annotations__ == {
|
||||
- 'fur_color': ForwardRef('str'),
|
||||
- 'name': ForwardRef('str'),
|
||||
- 'tail': ForwardRef('bool'),
|
||||
- 'voice': ForwardRef('str'),
|
||||
+ 'fur_color': typing.ForwardRef('str'),
|
||||
+ 'name': typing.ForwardRef('str'),
|
||||
+ 'tail': typing.ForwardRef('bool'),
|
||||
+ 'voice': typing.ForwardRef('str'),
|
||||
}
|
||||
|
||||
|
||||
|
||||
From 762584effacd447b23688acf9cbc70e453fd9601 Mon Sep 17 00:00:00 2001
|
||||
From: Noel Evans <noelevans@gmail.com>
|
||||
Date: Wed, 25 Nov 2020 23:35:59 +0000
|
||||
Subject: [PATCH 3/3] Simplify change using get_type_hints
|
||||
|
||||
---
|
||||
.../src_py3/test_typing_extensions.py | 43 ++++---------------
|
||||
1 file changed, 8 insertions(+), 35 deletions(-)
|
||||
|
||||
diff --git a/typing_extensions/src_py3/test_typing_extensions.py b/typing_extensions/src_py3/test_typing_extensions.py
|
||||
index 1c02877..b89b396 100644
|
||||
--- a/typing_extensions/src_py3/test_typing_extensions.py
|
||||
+++ b/typing_extensions/src_py3/test_typing_extensions.py
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
OLD_GENERICS = False
|
||||
try:
|
||||
- from typing import _type_vars, _next_in_mro, _type_check # noqa
|
||||
+ from typing import _type_vars, _next_in_mro, _type_check # noqa
|
||||
except ImportError:
|
||||
OLD_GENERICS = True
|
||||
|
||||
@@ -71,9 +71,6 @@
|
||||
# For checks reliant on Python 3.6 syntax changes (e.g. classvar)
|
||||
PY36 = sys.version_info[:2] >= (3, 6)
|
||||
|
||||
-# For checks reliant on Python 3.10
|
||||
-PY3_10 = sys.version_info[:2] >= (3, 10)
|
||||
-
|
||||
# Protocols are hard to backport to the original version of typing 3.5.0
|
||||
HAVE_PROTOCOLS = sys.version_info[:3] != (3, 5, 0)
|
||||
|
||||
@@ -1519,6 +1516,7 @@ def test_typeddict_errors(self):
|
||||
def test_py36_class_syntax_usage(self):
|
||||
self.assertEqual(LabelPoint2D.__name__, 'LabelPoint2D')
|
||||
self.assertEqual(LabelPoint2D.__module__, __name__)
|
||||
+ self.assertEqual(get_type_hints(LabelPoint2D), {'x': int, 'y': int, 'label': str})
|
||||
self.assertEqual(LabelPoint2D.__bases__, (dict,))
|
||||
self.assertEqual(LabelPoint2D.__total__, True)
|
||||
self.assertNotIsSubclass(LabelPoint2D, typing.Sequence)
|
||||
@@ -1527,13 +1525,6 @@ def test_py36_class_syntax_usage(self):
|
||||
self.assertEqual(not_origin['y'], 1)
|
||||
other = LabelPoint2D(x=0, y=1, label='hi')
|
||||
self.assertEqual(other['label'], 'hi')
|
||||
- if PY3_10:
|
||||
- self.assertEqual(LabelPoint2D.__annotations__, {
|
||||
- 'x': typing.ForwardRef('int'),
|
||||
- 'y': typing.ForwardRef('int'),
|
||||
- 'label': str})
|
||||
- else:
|
||||
- self.assertEqual(LabelPoint2D.__annotations__, {'x': int, 'y': int, 'label': str})
|
||||
|
||||
def test_pickle(self):
|
||||
global EmpD # pickle wants to reference the class by name
|
||||
@@ -1574,43 +1565,25 @@ def test_optional_keys(self):
|
||||
def test_keys_inheritance(self):
|
||||
assert BaseAnimal.__required_keys__ == frozenset(['name'])
|
||||
assert BaseAnimal.__optional_keys__ == frozenset([])
|
||||
+ assert get_type_hints(BaseAnimal) == {'name': str}
|
||||
|
||||
assert Animal.__required_keys__ == frozenset(['name'])
|
||||
assert Animal.__optional_keys__ == frozenset(['tail', 'voice'])
|
||||
-
|
||||
- assert Cat.__required_keys__ == frozenset(['name', 'fur_color'])
|
||||
- assert Cat.__optional_keys__ == frozenset(['tail', 'voice'])
|
||||
-
|
||||
- @skipUnless(PY36 and not PY3_10, 'Python 3.6 and < 3.10 required')
|
||||
- def test_keys_inheritance_before_postponed_annotation_eval(self):
|
||||
- assert BaseAnimal.__annotations__ == {'name': str}
|
||||
- assert Animal.__annotations__ == {
|
||||
+ assert get_type_hints(Animal) == {
|
||||
'name': str,
|
||||
'tail': bool,
|
||||
'voice': str,
|
||||
}
|
||||
- assert Cat.__annotations__ == {
|
||||
+
|
||||
+ assert Cat.__required_keys__ == frozenset(['name', 'fur_color'])
|
||||
+ assert Cat.__optional_keys__ == frozenset(['tail', 'voice'])
|
||||
+ assert get_type_hints(Cat) == {
|
||||
'fur_color': str,
|
||||
'name': str,
|
||||
'tail': bool,
|
||||
'voice': str,
|
||||
}
|
||||
|
||||
- @skipUnless(PY3_10, 'Python 3.10 required')
|
||||
- def test_keys_inheritance_with_postponed_annotation_eval(self):
|
||||
- assert BaseAnimal.__annotations__ == {'name': typing.ForwardRef('str')}
|
||||
- assert Animal.__annotations__ == {
|
||||
- 'name': typing.ForwardRef('str'),
|
||||
- 'tail': typing.ForwardRef('bool'),
|
||||
- 'voice': typing.ForwardRef('str'),
|
||||
- }
|
||||
- assert Cat.__annotations__ == {
|
||||
- 'fur_color': typing.ForwardRef('str'),
|
||||
- 'name': typing.ForwardRef('str'),
|
||||
- 'tail': typing.ForwardRef('bool'),
|
||||
- 'voice': typing.ForwardRef('str'),
|
||||
- }
|
||||
-
|
||||
|
||||
@skipUnless(TYPING_3_5_3, "Python >= 3.5.3 required")
|
||||
class AnnotatedTests(BaseTestCase):
|
@ -1,42 +0,0 @@
|
||||
From 240d811b00fb1cedfc42848e6efa6137bf009e8d Mon Sep 17 00:00:00 2001
|
||||
From: Fidget-Spinner <28750310+Fidget-Spinner@users.noreply.github.com>
|
||||
Date: Sat, 2 Jan 2021 23:26:26 +0800
|
||||
Subject: [PATCH] Update test_typing_extensions.py
|
||||
|
||||
---
|
||||
typing_extensions/src_py3/test_typing_extensions.py | 8 +++++---
|
||||
1 file changed, 5 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/typing_extensions/src_py3/test_typing_extensions.py b/typing_extensions/src_py3/test_typing_extensions.py
|
||||
index b89b396..98d02a0 100644
|
||||
--- a/typing_extensions/src_py3/test_typing_extensions.py
|
||||
+++ b/typing_extensions/src_py3/test_typing_extensions.py
|
||||
@@ -51,6 +51,7 @@
|
||||
TYPING_3_5_1 = TYPING_LATEST or sys.version_info[:3] >= (3, 5, 1)
|
||||
TYPING_3_5_3 = TYPING_LATEST or sys.version_info[:3] >= (3, 5, 3)
|
||||
TYPING_3_6_1 = TYPING_LATEST or sys.version_info[:3] >= (3, 6, 1)
|
||||
+TYPING_3_10_0 = TYPING_LATEST or sys.version_info[:3] >= (3, 10, 0)
|
||||
|
||||
# For typing versions where issubclass(...) and
|
||||
# isinstance(...) checks are forbidden.
|
||||
@@ -1240,8 +1241,9 @@ class P(PR[int, str], Protocol):
|
||||
self.assertIsSubclass(P, PR)
|
||||
with self.assertRaises(TypeError):
|
||||
PR[int]
|
||||
- with self.assertRaises(TypeError):
|
||||
- PR[int, 1]
|
||||
+ if not TYPING_3_10_0:
|
||||
+ with self.assertRaises(TypeError):
|
||||
+ PR[int, 1]
|
||||
class P1(Protocol, Generic[T]):
|
||||
def bar(self, x: T) -> str: ...
|
||||
class P2(Generic[T], Protocol):
|
||||
@@ -1254,7 +1256,7 @@ class Test:
|
||||
def bar(self, x: str) -> str:
|
||||
return x
|
||||
self.assertIsInstance(Test(), PSub)
|
||||
- if TYPING_3_5_3:
|
||||
+ if TYPING_3_5_3 and not TYPING_3_10_0:
|
||||
with self.assertRaises(TypeError):
|
||||
PR[int, ClassVar]
|
||||
|
Loading…
Reference in new issue