Skip to content

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

Closed
@OddBloke

Description

@OddBloke

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions