-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
MyPy is nondeterministic across runs #16979
Comments
I'm not sure if this example reveals the same underlying issue, and I don't know how to simplify it further, but this is also non-deterministic across runs with # mypy: no-incremental, disable-error-code=empty-body
from __future__ import annotations
import typing_extensions as t
from functools import total_ordering
T = t.TypeVar("T", bound="_SupportsCompare")
U = t.TypeVar("U", bound="_SupportsCompare")
@total_ordering
class _SupportsCompare(t.Protocol):
def __lt__(self, other: t.Any, /) -> bool: ...
class Comparable(_SupportsCompare):
@t.override
def __lt__(self, other: t.Any, /) -> bool: ...
class A(t.Generic[T, U]):
@t.overload
def __init__(self: A[T, T], a: T, b: T, /) -> None: ... # type: ignore[overload-overlap]
@t.overload
def __init__(self: A[T, U], a: T, b: U, /) -> t.Never: ...
def __init__(self, a: T, b: T | U, /) -> None: ...
comparable: Comparable = Comparable()
reveal_type(A(1, 1))
reveal_type(A(comparable, comparable))
reveal_type(A(1, comparable))
reveal_type(A(comparable, 1)) Tried on both 1.8.0 and master on the playground. The output is non-deterministically one of the following:
|
Thanks for the repros! I haven't yet looked in wjakob's but bzoracler's non-determinism seems to be coming from Slightly more minimised version:
|
Hmm maybe issue is non-commutativity in join_types |
I think something like this could fix:
|
@hauntsaninja I applied your patch. It unfortunately does not fix the issue, the type checker fails roughly ~1/3-1/2 of the time. |
Yeah, I haven't looked at your repro yet, possibly it could be an entirely different thing from bzoracler's |
Bug Report
I'm observing nondeterminism in MyPy runs on one of my programs. Sometimes, it accepts a file, sometimes it doesn't. Once it has accepted a file it seems to cache this solution, and I need to wipe
.mypy_cache
to be able to reproduce the random behavior again.To Reproduce
Download and extract the following archive (repro.tar.gz), which contains stubs from a library I am developing along with a
test.py
file to be checked.This is output from an actual run on my end:
Details on setup: mypy 1.8.0 (compiled: yes), Python 3.12.2, on an Apple M1 laptop (macOS 16.6.2). The machine is and has been perfectly stable. That is to say: I don't expect cosmic rays or RAM corruption to be responsible ;).
The text was updated successfully, but these errors were encountered: