Skip to content

Variable-length tuple doesn't narrow in isinstance #15443

@A5rocks

Description

@A5rocks

Bug Report

This may be a duplicate but I couldn't find any.

See the title for a short description or the short reproduction attached.

To Reproduce

a: object
b: tuple[type[int], ...]

if isinstance(a, b):
    reveal_type(a)

Expected Behavior

main.py:5: note: Revealed type is "builtins.int"
Success: no issues found in 1 source file

Actual Behavior

main.py:5: note: Revealed type is "builtins.object"
Success: no issues found in 1 source file

This works, however:

a: object
b: tuple[type[int]]

if isinstance(a, b):
    reveal_type(a)

Your Environment

https://mypy-play.net/?mypy=latest&python=3.11&gist=050eb94523510217a3bf91e9977539d0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-narrowingConditional type narrowing / binder

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions