diff options
author | Yurii Karabas <1998uriyyo@gmail.com> | 2021-07-30 12:56:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-30 12:56:12 (GMT) |
commit | 7b975f81e4dba70a42c6279539a7fcfe4211b4c0 (patch) | |
tree | 2d4537b5f27925541c842286170601906a0dde7f /Lib/typing.py | |
parent | 6ff890380971752299325bd28eab80ec936975cf (diff) | |
download | cpython-7b975f81e4dba70a42c6279539a7fcfe4211b4c0.zip cpython-7b975f81e4dba70a42c6279539a7fcfe4211b4c0.tar.gz cpython-7b975f81e4dba70a42c6279539a7fcfe4211b4c0.tar.bz2 |
bpo-44761: Change default value of NewType __module__ attr (GH-27406)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index f07b00f..2826525 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1387,11 +1387,11 @@ def _no_init(self, *args, **kwargs): if type(self)._is_protocol: raise TypeError('Protocols cannot be instantiated') -def _callee(depth=2, default=None): +def _caller(depth=1, default='__main__'): try: - return sys._getframe(depth).f_globals['__name__'] + return sys._getframe(depth + 1).f_globals.get('__name__', default) except (AttributeError, ValueError): # For platforms without _getframe() - return default + return None def _allow_reckless_class_checks(depth=3): @@ -2395,8 +2395,10 @@ class NewType: if '.' in name: name = name.rpartition('.')[-1] self.__name__ = name - self.__module__ = _callee(default='typing') self.__supertype__ = tp + def_mod = _caller() + if def_mod != 'typing': + self.__module__ = def_mod def __repr__(self): return f'{self.__module__}.{self.__qualname__}' |