Skip to content

Context causes invalid type argument value to be inferred #360

Closed
@JukkaL

Description

@JukkaL

The type checker may use context to infer an invalid type variable value for a type variable such as AnyStr:

from typing import AnyStr

def f(x: AnyStr) -> AnyStr:
    if isinstance(x, str):
        return 'foo'
    else:
        return b'zar'

print(repr(f(''))) # Type argument 1 of "f" has incompatible value "object"

We should probably not use type context in cases like this when the type variable is not used within a generic type.

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