Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-40397: Refactor typing._GenericAlias #19719

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into refactor-typing-generic-alias
  • Loading branch information
serhiy-storchaka committed May 2, 2020
commit f18888a4ce8d887be14d1fdb1ba60e4173505075
9 changes: 8 additions & 1 deletion 9 Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,13 @@ def copy_with(self, params):
return self.__class__(self.__origin__, params, name=self._name, inst=self._inst)

def __repr__(self):
if (self.__origin__ == Union and len(self.__args__) == 2
and type(None) in self.__args__):
if self.__args__[0] is not type(None):
arg = self.__args__[0]
else:
arg = self.__args__[1]
return (f'typing.Optional[{_type_repr(arg)}]')
if self._name:
name = 'typing.' + self._name
else:
Expand Down Expand Up @@ -1421,7 +1428,7 @@ def get_args(tp):
"""
if isinstance(tp, _AnnotatedAlias):
return (tp.__origin__,) + tp.__metadata__
if isinstance(tp, (_BaseGenericAlias, GenericAlias)):
if isinstance(tp, (_GenericAlias, GenericAlias)):
res = tp.__args__
if tp.__origin__ is collections.abc.Callable and res[0] is not Ellipsis:
res = (list(res[:-1]), res[-1])
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.