Skip to content

Commit 3a98bbf

Browse files
asottilemiss-islington
authored andcommitted
[3.7] bpo-36983: Fix typing.__all__ and add test for exported names (GH-13456) (GH-13662)
https://bugs.python.org/issue36983 Fixes issue 36983
1 parent 4e1e887 commit 3a98bbf

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Lib/test/test_typing.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,30 @@ def test_all(self):
26652665
self.assertIn('SupportsBytes', a)
26662666
self.assertIn('SupportsComplex', a)
26672667

2668+
def test_all_exported_names(self):
2669+
import typing
2670+
2671+
actual_all = set(typing.__all__)
2672+
computed_all = {
2673+
k for k, v in vars(typing).items()
2674+
# explicitly exported, not a thing with __module__
2675+
if k in actual_all or (
2676+
# avoid private names
2677+
not k.startswith('_') and
2678+
# avoid things in the io / re typing submodules
2679+
k not in typing.io.__all__ and
2680+
k not in typing.re.__all__ and
2681+
k not in {'io', 're'} and
2682+
# there's a few types and metaclasses that aren't exported
2683+
not k.endswith(('Meta', '_contra', '_co')) and
2684+
not k.upper() == k and
2685+
# but export all things that have __module__ == 'typing'
2686+
getattr(v, '__module__', None) == typing.__name__
2687+
)
2688+
}
2689+
self.assertSetEqual(computed_all, actual_all)
2690+
2691+
26682692

26692693
if __name__ == '__main__':
26702694
main()

Lib/typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'Any',
3737
'Callable',
3838
'ClassVar',
39+
'ForwardRef',
3940
'Generic',
4041
'Optional',
4142
'Tuple',
@@ -79,11 +80,13 @@
7980
'SupportsRound',
8081

8182
# Concrete collection types.
83+
'ChainMap',
8284
'Counter',
8385
'Deque',
8486
'Dict',
8587
'DefaultDict',
8688
'List',
89+
'OrderedDict',
8790
'Set',
8891
'FrozenSet',
8992
'NamedTuple', # Not really a type.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add missing names to ``typing.__all__``: ``ChainMap``, ``ForwardRef``,
2+
``OrderedDict`` - by Anthony Sottile.

0 commit comments

Comments
 (0)