diff options
| author | HongWeipeng <hongweichen8888@sina.com> | 2020-04-21 04:01:53 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-20 21:01:53 +0100 |
| commit | a25a04fea5446b1712cde0cff556574be139285a (patch) | |
| tree | 934463e1c9cfd539287f99cd7fb496f141afa23a /Lib/typing.py | |
| parent | eba9f6155df59c9beed97fb5764c9f01dd941af0 (diff) | |
| download | cpython-git-a25a04fea5446b1712cde0cff556574be139285a.tar.gz | |
bpo-39942:Fix failure in `TypeVar` when missing `__name__` (GH-19616)
https://bugs.python.org/issue39942
Diffstat (limited to 'Lib/typing.py')
| -rw-r--r-- | Lib/typing.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index df3650001e..9383fb8ff3 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -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 |
