You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type error randomly raised when using a decorator and a type: ignore comment #18125
Thanks! I can reproduce this locally. This is certainly a weird one!
So far I've narrowed this down to some non-deterministic behavior of is_subtype (specifically during this invocation).
What's quite interesting is that the nondeterministic behavior isn't just between mypy runs, but also between invocations of is_subtype with the same arguments during the same run (here's a video demo in my debugger).
Okay, this is really indeterminate. mypy.solve.solve_one is order-sensitive and iterates over sets. The following patch (not a fix, but only a proof) makes mypy output on this snippet completely reproducible.
diff --git a/mypy/solve.py b/mypy/solve.py
index 57988790a..a6d9cfcd7 100644
--- a/mypy/solve.py+++ b/mypy/solve.py@@ -214,7 +214,7 @@ def solve_iteratively(
break
# Solve each solvable type variable separately.
s_batch.remove(solvable_tv)
- result = solve_one(lowers[solvable_tv], uppers[solvable_tv])+ result = solve_one(sorted(lowers[solvable_tv], key=str), sorted(uppers[solvable_tv], key=str))
solutions[solvable_tv] = result
if result is None:
# TODO: support backtracking lower/upper bound choices and order within SCCs.
The problematic case is solving the following set of constraints:
for Self`1667 where Self`0 has default=Any, upper_bound=p.WrapModelValidator. If the iteration starts with Self`0, we solve 1677 to Any, otherwise we conclude that deps can't be satisfied (None).
This problem stems from non-commutative join and meet implementation.
Activity
brianschubert commentedon Nov 9, 2024
Thanks! I can reproduce this locally. This is certainly a weird one!
So far I've narrowed this down to some non-deterministic behavior of
is_subtype(specifically during this invocation).What's quite interesting is that the nondeterministic behavior isn't just between mypy runs, but also between invocations of
is_subtypewith the same arguments during the same run (here's a video demo in my debugger).sterliakov commentedon Apr 22, 2025
Okay, this is really indeterminate.
mypy.solve.solve_oneis order-sensitive and iterates over sets. The following patch (not a fix, but only a proof) makesmypyoutput on this snippet completely reproducible.The problematic case is solving the following set of constraints:
for
Self`1667whereSelf`0hasdefault=Any, upper_bound=p.WrapModelValidator. If the iteration starts withSelf`0, we solve 1677 toAny, otherwise we conclude that deps can't be satisfied (None).This problem stems from non-commutative join and meet implementation.
hauntsaninja commentedon Apr 22, 2025
Ah I ran into that in #16979 (comment) as well
Fix commutativity of join between TypeType and TypeVar
hauntsaninja commentedon May 26, 2025
Spent some time today looking at a few of these nondeterminism issues.
#19149 is a fix for this (it makes mypy consistently emit the error)
Fix nondeterministic type checking by making join between TypeType an…