You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression with narrowing with multiple hasattr #20596
[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
I have a patch that fixes this that does some reordering of how things get set in the output_map in propagate_up_typemap_info... but it doesn't feel principled and I don't like it
Maybe if I can clean up some more type map logic a better fix will reveal itself
Activity
Fix regression with narrowing and multiple hasattr checks (issue pyth…
James-4u commentedon Jan 20, 2026
hello @hauntsaninja requesting your reviews 😄
https://github.com/python/mypy/compare/master...SmartDever02:fix-issue-20596-hasattr-narrowing?expand=1
hauntsaninja commentedon Jan 29, 2026
I have a patch that fixes this that does some reordering of how things get set in the output_map in
propagate_up_typemap_info... but it doesn't feel principled and I don't like itMaybe if I can clean up some more type map logic a better fix will reveal itself
Correctly aggregate narrowing information on parent expressions (pyth…
Correctly aggregate narrowing information on parent expressions (#21206)