ruff
da069aa0 - [red-knot] Infer `lambda` expression (#16547)

Commit
189 days ago
[red-knot] Infer `lambda` expression (#16547) ## Summary Part of https://github.com/astral-sh/ruff/issues/15382 This PR adds support for inferring the `lambda` expression and return the `CallableType`. Currently, this is only limited to inferring the parameters and a todo type for the return type. For posterity, I tried using the `file_expression_type` to infer the return type of lambda but it would always lead to cycle. The main reason is that in `infer_parameter_definition`, the default expression is being inferred using `file_expression_type`, which is correct, but it then Take the following source code as an example: ```py lambda x=1: x ``` Here's how the code will flow: * `infer_scope_types` for the global scope * `infer_lambda_expression` * `infer_expression` for the default value `1` * `file_expression_type` for the return type using the body expression. This is because the body creates it's own scope * `infer_scope_types` (lambda body scope) * `infer_name_load` for the symbol `x` whose visible binding is the lambda parameter `x` * `infer_parameter_definition` for parameter `x` * `file_expression_type` for the default value `1` * `infer_scope_types` for the global scope because of the default expression This will then reach to `infer_definition` for the parameter `x` again which then creates the cycle. ## Test Plan Add tests around `lambda` expression inference.
Author
Parents
Loading