Skip to content

Conversation

@hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Jan 28, 2026

We now more accurately model reachability for impossible checks. We also avoid allowing tuples and X | Y syntax in situations where they don't work at runtime.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hauntsaninja hauntsaninja marked this pull request as draft January 29, 2026 01:52
@hauntsaninja
Copy link
Collaborator Author

Primer here is a lie, exposes a reachability issue. Will put in a fix

@github-actions

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator Author

Okay great, #20677 fixes a lot of the false unreachability

@hauntsaninja hauntsaninja marked this pull request as ready for review January 29, 2026 19:22
@hauntsaninja hauntsaninja requested a review from JukkaL January 29, 2026 19:22
@hauntsaninja
Copy link
Collaborator Author

steam is an improvement (that I have a test case for)
static-frame looks like a true positive (either need to explicitly inherit from protocol or add a protocol annotation on the container), possible it was previously unreachable?
beartype is acceptable, probably needs to annotate the collection

@github-actions

This comment has been minimized.

yield values
raise

class A: ...
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't change behaviour on f1,f2,g1,g2

but there is a latent pre-existing issue in conditional_types that could be exposed in the future, see discussion in #20677 (comment)

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

beartype (https://github.com/beartype/beartype)
+ beartype/_util/hint/pep/proposal/pep484585/generic/pep484585genget.py:981: error: Item "object" of "object | Any" has no attribute "__qualname__"  [union-attr]
+ beartype/_util/hint/pep/utilpepsign.py:481: error: Item "object" of "object | Any" has no attribute "__qualname__"  [union-attr]

steam.py (https://github.com/Gobot1234/steam.py)
+ steam/_const.py:189: error: Unused "type: ignore" comment  [unused-ignore]

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/interface.py:1577: error: Argument "cls_interface" to "gen_from_accessor" of "InterfaceRecord" has incompatible type "type[object]"; expected "type[Interface]"  [arg-type]

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can you add a description that explains the primary behavioral changes?

# Type[A] means "any type that is a subtype of A" rather than "precisely type A"
# we indicate this by setting is_upper_bound flag
is_upper_bound = True
if isinstance(typ.item, NoneType):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about final classes?

return TypeRange(typ, is_upper_bound=False)
if isinstance(typ, Instance) and typ.type.fullname == "builtins.type":
object_type = Instance(typ.type.mro[-1], [])
return TypeRange(object_type, is_upper_bound=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final classes?

@hauntsaninja
Copy link
Collaborator Author

Thanks, I added some description.

The final classes stuff is in code I'm not really changing.
I do plan to work on it, but it is blocked by pre-existing issue in conditional_types as I mention here: #20675 (comment)

This diff is probably best reviewed with the "ignore whitespace" setting. In the big part of the diff the net new code is really just these two bits: https://github.com/python/mypy/pull/20675/files#diff-f96a2d6138bc6cdf2a07c4d37f6071cc25c1631afc107e277a28d5b59fc0ef04R7976-R7984

I had to split the function because the forms allowed in isinstance(x, ...) and type(...) = x are different

@hauntsaninja hauntsaninja merged commit eba9a4c into python:master Jan 30, 2026
23 checks passed
@hauntsaninja hauntsaninja deleted the narrow57 branch January 30, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants