bpo-36983: Fix typing.__all__ and add test for exported names (GH-13456) · python/cpython@d30da5d

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()