Skip to content

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

Merged
hauntsaninja merged 8 commits into
python:masterfrom
hauntsaninja:nondet
Jun 1, 2025
Merged

Fix nondeterministic type checking by making join with explicit Protocol and type promotion commute#18402
hauntsaninja merged 8 commits into
python:masterfrom
hauntsaninja:nondet

Conversation

@hauntsaninja

@hauntsaninjahauntsaninja commented Jan 1, 2025

Copy link
Copy Markdown
Collaborator

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
@github-actions

This comment has been minimized.

@hauntsaninja

Copy link
Copy Markdown
CollaboratorAuthor

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

@github-actions

This comment has been minimized.

@hauntsaninjahauntsaninja changed the title Fix nondeterministic type checking involving noncommutative joinFix nondeterministic type checking by making join with explicit Protocol and type promotion commuteMay 26, 2025
@hauntsaninja

Copy link
Copy Markdown
CollaboratorAuthor

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)

@JukkaLJukkaL left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment threadtest-data/unit/check-inference.test
Comment threadtest-data/unit/check-inference.test
Comment threadtest-data/unit/check-protocols.test
@github-actions

Copy link
Copy Markdown
Contributor

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:masterJun 1, 2025
@hauntsaninja
hauntsaninja deleted the nondet branch June 1, 2025 01:08
Sign up for freeto 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

@hauntsaninja@JukkaL