From cb74eb536c4cef55876e5dc99c1c15239ceb388c Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 29 May 2019 11:19:38 -0700 Subject: [PATCH] bpo-36983: Fix typing.__all__ and add test for exported names (GH-13456) https://bugs.python.org/issue36983 --- Lib/test/test_typing.py | 24 +++++++++++++++++++ Lib/typing.py | 1 + .../2019-05-20-20-41-30.bpo-36983.hz-fLr.rst | 1 + 3 files changed, 26 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-05-20-20-41-30.bpo-36983.hz-fLr.rst diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 4843d6faf70414..904f02040c3862 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -2642,6 +2642,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() diff --git a/Lib/typing.py b/Lib/typing.py index f2b6aaf3a9278c..7c0b1f64457707 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -90,6 +90,7 @@ 'NewType', 'no_type_check', 'no_type_check_decorator', + 'NoReturn', 'overload', 'Text', 'TYPE_CHECKING', diff --git a/Misc/NEWS.d/next/Library/2019-05-20-20-41-30.bpo-36983.hz-fLr.rst b/Misc/NEWS.d/next/Library/2019-05-20-20-41-30.bpo-36983.hz-fLr.rst new file mode 100644 index 00000000000000..388a42f8e5032c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-05-20-20-41-30.bpo-36983.hz-fLr.rst @@ -0,0 +1 @@ +Add missing names to ``typing.__all__``: ``NoReturn`` - by Anthony Sottile.