bpo-39942:Fix failure in TypeVar when missing __name__ (GH-19616)

https://bugs.python.org/issue39942
This commit is contained in:
HongWeipeng 2020-04-21 04:01:53 +08:00 committed by GitHub
parent eba9f6155d
commit a25a04fea5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View file

@ -606,7 +606,10 @@ class TypeVar(_Final, _Immutable, _root=True):
self.__bound__ = _type_check(bound, "Bound must be a type.")
else:
self.__bound__ = None
def_mod = sys._getframe(1).f_globals['__name__'] # for pickling
try:
def_mod = sys._getframe(1).f_globals.get('__name__', '__main__') # for pickling
except (AttributeError, ValueError):
def_mod = None
if def_mod != 'typing':
self.__module__ = def_mod