Skip to content

Wrong type narrowing when using type without an argument in isinstance call #13462

Closed
@twoertwein

Description

@twoertwein

To Reproduce

from typing import TypeVar

T = TypeVar("T")


def fun(x: T, klass: type) -> T:
    if not isinstance(x, klass):
        raise TypeError
    return x

Expected Behavior

No error.

Actual Behavior

error: Incompatible return value type (got "object", expected "T") [return-value]

Your Environment

  • Mypy version used: 0.971

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongfalse-positivemypy gave an error on correct codetopic-type-narrowingConditional type narrowing / binder

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions