Skip to content

Regression with narrowing with multiple hasattr #20596

@hauntsaninja

Description

@hauntsaninja
[case testMultipleHasAttr]
# flags: --warn-unreachable
from __future__ import annotations
from typing import Any

def len(obj: object) -> Any: ...

def f(x: type | str):
    if (
        hasattr(x, "__origin__")
        and x.__origin__ is list
        and hasattr(x, "__args__")
        and len(x.__args__) == 1
    ):
        reveal_type(x.__args__[0])  # N: Revealed type is "Any"
[builtins fixtures/module.pyi]

Regression introduced in #20492 that I don't yet have fixed in my commit stack. Probably just need to manage the conditional type maps a little more carefully

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