Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

type of Union containing Any is incorrectly inferred after an isinstance check #1720

Copy link
Copy link
@sharmaeklavya2

Description

@sharmaeklavya2
Issue body actions

union_any.py:

from typing import Any, Union

def func(v):
    # type: (Union[int, Any]) -> str
    if isinstance(v, int):
        s = hex(v)
    else:
        s = str(v).lower()
    return "key:" + s

mypy union_any.py:

union_any.py: note: In function "func":
union_any.py:8: error: No overload variant of "str" matches argument types [Union[<ERROR>, void]]

mypy --py2 union_any.py:

union_any.py: note: In function "func":
union_any.py:8: error: Argument 1 to "str" has incompatible type "Union[object, None]"; expected "object"

I discovered this when I used a class which was defined in some library which did not have stubs and I was using --silent-imports.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.