Skip to content

Commit d30da5d

Browse files
asottilemiss-islington
authored andcommitted
bpo-36983: Fix typing.__all__ and add test for exported names (GH-13456)
https://bugs.python.org/issue36983
1 parent 34f4f5e commit d30da5d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Diff for: Lib/test/test_typing.py

+24
Original file line numberDiff line numberDiff line change
@@ -3605,6 +3605,30 @@ def test_all(self):
36053605
self.assertIn('SupportsBytes', a)
36063606
self.assertIn('SupportsComplex', a)
36073607

3608+
def test_all_exported_names(self):
3609+
import typing
3610+
3611+
actual_all = set(typing.__all__)
3612+
computed_all = {
3613+
k for k, v in vars(typing).items()
3614+
# explicitly exported, not a thing with __module__
3615+
if k in actual_all or (
3616+
# avoid private names
3617+
not k.startswith('_') and
3618+
# avoid things in the io / re typing submodules
3619+
k not in typing.io.__all__ and
3620+
k not in typing.re.__all__ and
3621+
k not in {'io', 're'} and
3622+
# there's a few types and metaclasses that aren't exported
3623+
not k.endswith(('Meta', '_contra', '_co')) and
3624+
not k.upper() == k and
3625+
# but export all things that have __module__ == 'typing'
3626+
getattr(v, '__module__', None) == typing.__name__
3627+
)
3628+
}
3629+
self.assertSetEqual(computed_all, actual_all)
3630+
3631+
36083632

36093633
if __name__ == '__main__':
36103634
main()

Diff for: Lib/typing.py

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'Callable',
3636
'ClassVar',
3737
'Final',
38+
'ForwardRef',
3839
'Generic',
3940
'Literal',
4041
'Optional',
@@ -81,11 +82,13 @@
8182
'SupportsRound',
8283

8384
# Concrete collection types.
85+
'ChainMap',
8486
'Counter',
8587
'Deque',
8688
'Dict',
8789
'DefaultDict',
8890
'List',
91+
'OrderedDict',
8992
'Set',
9093
'FrozenSet',
9194
'NamedTuple', # Not really a type.
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)