Skip to content

Commit cb74eb5

Browse files
committed
bpo-36983: Fix typing.__all__ and add test for exported names (GH-13456)
https://bugs.python.org/issue36983
1 parent 4f06dae commit cb74eb5

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Lib/test/test_typing.py

+24
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,30 @@ def test_all(self):
26422642
self.assertIn('SupportsBytes', a)
26432643
self.assertIn('SupportsComplex', a)
26442644

2645+
def test_all_exported_names(self):
2646+
import typing
2647+
2648+
actual_all = set(typing.__all__)
2649+
computed_all = {
2650+
k for k, v in vars(typing).items()
2651+
# explicitly exported, not a thing with __module__
2652+
if k in actual_all or (
2653+
# avoid private names
2654+
not k.startswith('_') and
2655+
# avoid things in the io / re typing submodules
2656+
k not in typing.io.__all__ and
2657+
k not in typing.re.__all__ and
2658+
k not in {'io', 're'} and
2659+
# there's a few types and metaclasses that aren't exported
2660+
not k.endswith(('Meta', '_contra', '_co')) and
2661+
not k.upper() == k and
2662+
# but export all things that have __module__ == 'typing'
2663+
getattr(v, '__module__', None) == typing.__name__
2664+
)
2665+
}
2666+
self.assertSetEqual(computed_all, actual_all)
2667+
2668+
26452669

26462670
if __name__ == '__main__':
26472671
main()

Lib/typing.py

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
'NewType',
9191
'no_type_check',
9292
'no_type_check_decorator',
93+
'NoReturn',
9394
'overload',
9495
'Text',
9596
'TYPE_CHECKING',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add missing names to ``typing.__all__``: ``NoReturn`` - by Anthony Sottile.

0 commit comments

Comments
 (0)