Skip to content

Commit d911e40

Browse files
authored
bpo-32226: PEP 560: improve typing module (#4906)
This PR re-designs the internal typing API using the new PEP 560 features. However, there are only few minor changes in the public API.
1 parent d57f26c commit d911e40

File tree

5 files changed

+804
-1673
lines changed

5 files changed

+804
-1673
lines changed

Lib/dataclasses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ def _get_field(cls, a_name, a_type):
389389
if typing is not None:
390390
# This test uses a typing internal class, but it's the best
391391
# way to test if this is a ClassVar.
392-
if type(a_type) is typing._ClassVar:
392+
if (type(a_type) is typing._GenericAlias and
393+
a_type.__origin__ is typing.ClassVar):
393394
# This field is a ClassVar, so it's not a field.
394395
f._field_type = _FIELD_CLASSVAR
395396

Lib/test/libregrtest/refleak.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
135135
# Clear ABC registries, restoring previously saved ABC registries.
136136
abs_classes = [getattr(collections.abc, a) for a in collections.abc.__all__]
137137
abs_classes = filter(isabstract, abs_classes)
138-
if 'typing' in sys.modules:
139-
t = sys.modules['typing']
140-
# These classes require special treatment because they do not appear
141-
# in direct subclasses of collections.abc classes
142-
abs_classes = list(abs_classes) + [t.ChainMap, t.Counter, t.DefaultDict]
143138
for abc in abs_classes:
144139
for obj in abc.__subclasses__() + [abc]:
145140
obj._abc_registry = abcs.get(obj, WeakSet()).copy()

Lib/test/test_pydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ class C(typing.Generic[T], typing.Mapping[int, str]): ...
827827
'f\x08fo\x08oo\x08o(data: List[Any], x: int)'
828828
' -> Iterator[Tuple[int, Any]]')
829829
self.assertEqual(pydoc.render_doc(C).splitlines()[2],
830-
'class C\x08C(typing.Mapping)')
830+
'class C\x08C(collections.abc.Mapping, typing.Generic)')
831831

832832
def test_builtin(self):
833833
for name in ('str', 'str.translate', 'builtins.str',

0 commit comments

Comments
 (0)