Skip to content

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

Description

@twoertwein

To Reproduce

fromtypingimportTypeVarT=TypeVar("T")
deffun(x: T, klass: type) ->T:
ifnotisinstance(x, klass):
raiseTypeErrorreturnx

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