bpo-36983: Fix typing.__all__ and add test for exported names (GH-13456)
https://bugs.python.org/issue36983
This commit is contained in:
parent
34f4f5efea
commit
d30da5dd9a
|
@ -3605,6 +3605,30 @@ class AllTests(BaseTestCase):
|
||||||
self.assertIn('SupportsBytes', a)
|
self.assertIn('SupportsBytes', a)
|
||||||
self.assertIn('SupportsComplex', 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__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -35,6 +35,7 @@ __all__ = [
|
||||||
'Callable',
|
'Callable',
|
||||||
'ClassVar',
|
'ClassVar',
|
||||||
'Final',
|
'Final',
|
||||||
|
'ForwardRef',
|
||||||
'Generic',
|
'Generic',
|
||||||
'Literal',
|
'Literal',
|
||||||
'Optional',
|
'Optional',
|
||||||
|
@ -81,11 +82,13 @@ __all__ = [
|
||||||
'SupportsRound',
|
'SupportsRound',
|
||||||
|
|
||||||
# Concrete collection types.
|
# Concrete collection types.
|
||||||
|
'ChainMap',
|
||||||
'Counter',
|
'Counter',
|
||||||
'Deque',
|
'Deque',
|
||||||
'Dict',
|
'Dict',
|
||||||
'DefaultDict',
|
'DefaultDict',
|
||||||
'List',
|
'List',
|
||||||
|
'OrderedDict',
|
||||||
'Set',
|
'Set',
|
||||||
'FrozenSet',
|
'FrozenSet',
|
||||||
'NamedTuple', # Not really a type.
|
'NamedTuple', # Not really a type.
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Add missing names to ``typing.__all__``: ``ChainMap``, ``ForwardRef``,
|
||||||
|
``OrderedDict`` - by Anthony Sottile.
|
Loading…
Reference in New Issue