-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-39942:Fix TypeVar
fails when missing __name__
#19616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -606,7 +606,10 @@ def __init__(self, name, *constraints, bound=None, | |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's safe to assume There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think try:
module = sys._getframe(1).f_globals.get('__name__', '__main__')
except (AttributeError, ValueError):
module = None |
||
except (AttributeError, ValueError): | ||
def_mod = None | ||
if def_mod != 'typing': | ||
self.__module__ = def_mod | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Set "__main__" as the default module name when "__name__" is missing in | ||
:class:`typing.TypeVar`. Patch by Weipeng Hong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be more like the other tests