Skip to content

Any apparently not considered part of Union[Any, builtins.None] #3472

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

Closed
OddBloke opened this issue May 29, 2017 · 5 comments · Fixed by #3473
Closed

Any apparently not considered part of Union[Any, builtins.None] #3472

OddBloke opened this issue May 29, 2017 · 5 comments · Fixed by #3473
Labels
bug mypy got something wrong

Comments

@OddBloke
Copy link
Contributor

When running mypy --strict against the following code:

from typing import Any, Optional

class Test(object):

    def __init__(self) -> None:
        self.attr = "foo"  # type: Any

    def foo(self, do_it: bool) -> Optional[Any]:
        if do_it:
            return self.attr
        else:
            return None

I see the following warning:

testcase.py:11: warning: Returning Any from function with declared return type "Union[Any, builtins.None]"

This seems obviously incorrect. At the very least, it's a confusing error message.

Bisecting suggests that this behaviour was introduced in 4141d20.

@gvanrossum gvanrossum added the bug mypy got something wrong label May 30, 2017
@gvanrossum
Copy link
Member

That's @JukkaL's PR #3086.

@ilevkivskyi
Copy link
Member

I think the problem is not with Jukka's PR but in the logic of --warn-return-any. It should not emit warning if Any is a proper subtype of the declared return type. I have an idea for a very simple fix, if it will work, then I will make a PR shortly.

@ilevkivskyi
Copy link
Member

OK, here is the PR #3473

@OddBloke
Copy link
Contributor Author

Thanks all! When might we expect to see this in a release?

@JukkaL
Copy link
Collaborator

JukkaL commented May 30, 2017

We typically have a release every 2 months or so, so the next release could be June/Julyish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants