Change the return type of __reduce__ and __reduce_ex__ to Union[str, Tuple[Any, ...]]#3453
Merged
srittau merged 1 commit intopython:masterfrom Nov 10, 2019
MSeifert04:reduce-return-union
Merged
Change the return type of __reduce__ and __reduce_ex__ to Union[str, Tuple[Any, ...]]#3453srittau merged 1 commit intopython:masterfrom MSeifert04:reduce-return-union
srittau merged 1 commit intopython:masterfrom
MSeifert04:reduce-return-union
Conversation
srittau
reviewed
Nov 10, 2019
stdlib/2and3/builtins.pyi
Outdated
| def __sizeof__(self) -> int: ... | ||
| def __reduce__(self) -> Tuple[Any, ...]: ... | ||
| def __reduce__(self) -> Union[str, Tuple[Any, ...]]: ... | ||
| def __reduce_ex__(self, protocol: int) -> Tuple[Any, ...]: ... |
Collaborator
There was a problem hiding this comment.
Could you also add this to __reduce_ex__?
…Tuple[Any, ...]] This allows subclasses to return strings (which are allowed) from these methods without having mypy throwing an error.
Collaborator
This is fine in this case. Normally we prefer non-Union return types, because it means the caller needs to use |
srittau
approved these changes
Nov 10, 2019
Contributor
Author
|
Ah, thank you for the clarification! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows subclasses to return strings (which are allowed) from these
methods without having mypy throwing an error.
This fixes #3452
However this violates the following item from the Contributing file: