mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
bpo-44761: Change default value of NewType __module__ attr (GH-27406) (GH-27477)
(cherry picked from commit 7b975f81e4
)
Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
This commit is contained in:
parent
0cb470e622
commit
56122b0bba
2 changed files with 12 additions and 4 deletions
|
@ -1379,11 +1379,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):
|
||||
|
@ -2385,8 +2385,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__}'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue