Skip to content
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
Refactor __reduce__.
  • Loading branch information
serhiy-storchaka committed May 2, 2020
commit 5431d6d9bc89e2ed8718e81a29c65f6f38a4662e
16 changes: 9 additions & 7 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,13 +721,9 @@ def __reduce__(self):
origin = globals()[self._name]
else:
origin = self.__origin__
if (origin is Callable and
not (len(self.__args__) == 2 and self.__args__[0] is Ellipsis)):
args = list(self.__args__[:-1]), self.__args__[-1]
else:
args = tuple(self.__args__)
if len(args) == 1 and not isinstance(args[0], tuple):
args, = args
args = tuple(self.__args__)
if len(args) == 1 and not isinstance(args[0], tuple):
args, = args
return operator.getitem, (origin, args)

def __mro_entries__(self, bases):
Expand Down Expand Up @@ -787,6 +783,12 @@ def __repr__(self):
f'[[{", ".join([_type_repr(a) for a in self.__args__[:-1]])}], '
f'{_type_repr(self.__args__[-1])}]')

def __reduce__(self):
args = self.__args__
if not (len(args) == 2 and args[0] is ...):
args = list(args[:-1]), args[-1]
return operator.getitem, (Callable, args)


class _CallableType(_SpecialGenericAlias, _root=True):
def copy_with(self, params):
Expand Down