-
Notifications
You must be signed in to change notification settings - Fork 227
Closed
1 / 11 of 1 issue completed
Copy link
Description
While digging into an unrelated issue, I noticed that we are currently very likely to enter a salsa cycle when inferring the signature of a function literal.
The particular example I found involves the functools.cache decorator, whose definition is:
def cache(fn: Callable[..., _T]) -> _lru_cache_wrapper[_T]:
...Then when we infer the type of a function definition that is decorated with @cache:
@cache
def f(x: int) -> int:
...- We enter
infer_definition_typesforf. - We construct a
Type::FunctionTypefor the (undecorated) definition. - We apply the
@cachedecorator:- This requires checking whether
fis assignable toCallable[..., T]. To do that, we need the signature off. OverloadLiteral::raw_signaturecallsSignature::from_function, which callsParameters::from_parameters, which callsinfer_method_information, which callsinfer_definition_typesforf, to check iffis a generic method,@classmethod, or@staticmethod.
- This requires checking whether
We should see if there's a way to break that cycle. We might even consider not constructing the signatures lazily!
Reactions are currently unavailable