-
Notifications
You must be signed in to change notification settings - Fork 135
Description
ty panics with "infer_expression_type(Id(1401)): execute: too many cycle iterations" for the following example:
from typing import Self
class C:
def __init__(self: Self):
self.a = 0
def b(self: Self):
self.a = self.a + 1When inferring the type of the a attribute, we take bindings in all methods into account, so we infer a growing union of literals Unknown | Literal[0, 1, 2, 3, …] here. This is not really related to attribute accesses though. The same thing would happen if we had full fixpoint iteration for loops (I believe):
i = 0
while True:
i += 1
reveal_type(i)This was orginally reported by @Glyphack.
Comments by @carljm:
The simplest approach here is to dramatically reduce the maximum size of literal unions we support
The infrastructure for this is all already in place, so it’s literally just changing a number
The question is whether we want to be able to support larger explicit literal unions than we want to accumulate in fixpoint iteration
If so, then that requires more additional infrastructure complication
But I think we could set a literal-union size limit of anything under 200 (the salsa iteration limit) and make this too-many-iterations error go away
(But we’d still iterate that many times, and hundreds of iterations might not be great for perf)
Another approach would be to add complication to the cycle handling function of some query in that cycle so that if it sees a growing union of literals, it falls back sooner
And of course a third approach would just be to infer Unknown | int in the first place for undeclared = 1 instead of Unknown | Literal[1], and make the issue go away entirely