Skip to content

bpo-36983: Fix typing.__all__ and add test for exported names #13456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3605,6 +3605,30 @@ def test_all(self):
self.assertIn('SupportsBytes', a)
self.assertIn('SupportsComplex', a)

def test_all_exported_names(self):
import typing

actual_all = set(typing.__all__)
computed_all = {
k for k, v in vars(typing).items()
# explicitly exported, not a thing with __module__
if k in actual_all or (
# avoid private names
not k.startswith('_') and
# avoid things in the io / re typing submodules
k not in typing.io.__all__ and
k not in typing.re.__all__ and
k not in {'io', 're'} and
# there's a few types and metaclasses that aren't exported
not k.endswith(('Meta', '_contra', '_co')) and
not k.upper() == k and
# but export all things that have __module__ == 'typing'
getattr(v, '__module__', None) == typing.__name__
)
}
self.assertSetEqual(computed_all, actual_all)



if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'Callable',
'ClassVar',
'Final',
'ForwardRef',
'Generic',
'Literal',
'Optional',
Expand Down Expand Up @@ -81,11 +82,13 @@
'SupportsRound',

# Concrete collection types.
'ChainMap',
'Counter',
'Deque',
'Dict',
'DefaultDict',
'List',
'OrderedDict',
'Set',
'FrozenSet',
'NamedTuple', # Not really a type.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add missing names to ``typing.__all__``: ``ChainMap``, ``ForwardRef``,
``OrderedDict`` - by Anthony Sottile.