Inferring a type variable from a function passed to a union of generic callback protocols depends on which calls were checked earlier in the same process. The first call infers correctly; a later call matching the other protocol infers Never. With --num-workers this makes results nondeterministic, because it depends on which modules share a worker.
To Reproduce
Repro minimized using LLMs based on real world code. (playground)
main.py:23: note: Revealed type is "int"
main.py:24: note: Revealed type is "str"
Actual Behavior
main.py:23: note: Revealed type is "int"
main.py:24: note: Revealed type is "Never"
Swapping the last two lines gives str then Never; either call alone is correct.
With Callable[[T], None] | Callable[[T, int], None] instead of the protocols, both infer correctly.
Parallel mode: put the definitions in one module and the two calls (as x = first_arg(...)) in six modules each. Cold runs of mypy --num-workers=8 . then report between zero and four Need type annotation for "x" errors; 4 of 20 runs were clean on 2.3.0.
Your Environment
Mypy version used: 2.3.0, 2.4.0, master (2.5.0+dev.6a6979c49a96d677396fe6df7301c903c7bcc01e)
Activity