Skip to content
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

object.__reduce__ might return a string #3452

Closed
MSeifert04 opened this issue Nov 10, 2019 · 1 comment · Fixed by #3453
Closed

object.__reduce__ might return a string #3452

MSeifert04 opened this issue Nov 10, 2019 · 1 comment · Fixed by #3453
Labels
stubs: false positive Type checkers report false errors

Comments

@MSeifert04
Copy link
Contributor

MSeifert04 commented Nov 10, 2019

I have a type which returns a string in __reduce__ which leads to a mypy failure:

Return type "str" of "__reduce__" incompatible with return type "Tuple[Any, ...]" in supertype "object"

According to the __reduce__ documentation this method can return a string or a Tuple.

Would it make sense to change the typing to __reduce__(self) -> Union[str, Tuple[Any, ...]]: ...?

@MSeifert04 MSeifert04 changed the title object.__reduce__ returning a string object.__reduce__ might return a string Nov 10, 2019
@srittau
Copy link
Collaborator

srittau commented Nov 10, 2019

Same for __reduce_ex__. Makes sense, PR welcome!

@srittau srittau added size-small stubs: false positive Type checkers report false errors labels Nov 10, 2019
srittau pushed a commit that referenced this issue Nov 10, 2019
…Tuple[Any, ...]] (#3453)

This allows subclasses to return strings (which are allowed) from these
methods without having mypy throwing an error.

Closes #3452
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants