Skip to content

Fix nondeterministic type checking by making join with explicit Protocol and type promotion commute #18402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 1, 2025

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Jan 1, 2025

Fixes #16979 (bzoracler case only, OP case fixed by #19147)

See #16979 (comment)

@hauntsaninja hauntsaninja marked this pull request as draft January 1, 2025 22:01
@hauntsaninja hauntsaninja marked this pull request as ready for review May 25, 2025 22:51

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator Author

Hmm, false positive is because Collection actually has a long MRO. But the length of a protocol MRO doesn't really mean anything. So I will just change is_better

This comment has been minimized.

@hauntsaninja hauntsaninja changed the title Fix nondeterministic type checking involving noncommutative join Fix nondeterministic type checking by making join with explicit Protocol and type promotion commute May 26, 2025
@hauntsaninja
Copy link
Collaborator Author

cc @JukkaL one more nondeterminism PR!

hauntsaninja added a commit that referenced this pull request May 28, 2025
#19147)

I thought about doing this in `join_type_list`, but most callers look
like they do have some deterministic order.

Fixes #19121 (torchvision case only, haven't looked at xarray)

Fixes #16979 (OP case only, bzoracler case fixed by #18402)
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! Looks good overall, though the logic is getting pretty hard to follow. Left some comments about tests.

Copy link
Contributor

github-actions bot commented Jun 1, 2025

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

nox (https://github.com/wntrblm/nox): 1.46x slower (24.6s -> 35.9s in single noisy sample)

typeshed-stats (https://github.com/AlexWaygood/typeshed-stats): 1.57x slower (60.7s -> 95.0s in single noisy sample)

@hauntsaninja hauntsaninja merged commit 0ea8488 into python:master Jun 1, 2025
19 checks passed
@hauntsaninja hauntsaninja deleted the nondet branch June 1, 2025 01:08
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.

MyPy is nondeterministic across runs
2 participants