[red-knot] Infer lambda return type as Unknown#16695
Conversation
|
51cff8e to
7a2d2bd
Compare
|
I'm a bit unsure about the mypy_primer failure, the logs doesn't suggest anything obvious. I plan to look at it tomorrow morning. |
|
Is it possible that this PR is causing us to hang on one of the mypy_primer projects? I haven't checked to see if it's stopping on the same project every time |
|
mypy-primer is hitting a problem on |
|
On looking at this a bit more, I don't think we should go forward with landing this approach. I think instead, as I mentioned in Discord, we should simply record Useful inference of a lambda's return type will require a different approach, which does the inference of the body expression based on arguments at each call site, rather than eagerly computing a return type without knowing the argument types. I don't think anything from this approach would carry over to that, so I don't think it's worth making all function defaults standalone expressions just so that we can temporarily have slightly more information about lambda return types. |
Yeah, that makes sense. Thanks for looking into it, I'll update the PR to use |
7a2d2bd to
ce0194f
Compare
lambda expressionlambda return type as Unknown
* main: [playground] Avoid concurrent deployments (#16834) [red-knot] Infer `lambda` return type as `Unknown` (#16695) [red-knot] Move `name` field on parameter kind (#16830) [red-knot] Emit errors for more AST nodes that are invalid (or only valid in specific contexts) in type expressions (#16822) [playground] Use cursor for clickable elements (#16833) [red-knot] Deploy playground on main (#16832) Red Knot Playground (#12681) [syntax-errors] PEP 701 f-strings before Python 3.12 (#16543)
…r-instance * dcreager/two-phase-binding: (210 commits) Update docs clippy Fix docs with_self instead of push/pop_self Update crates/red_knot_python_semantic/src/types/call/arguments.rs lint Report conflicting forms for call as a whole, not for any signature Add conflicting form test case Use option<usize> Remove some unneeded clones evaluate_known_cases Infer types when constructing CallArgumentTypes Remove old comment Use VecDeques for arguments and types Fix tests Add comment Add some comments Use parameter_types for all special cases [playground] Avoid concurrent deployments (#16834) [red-knot] Infer `lambda` return type as `Unknown` (#16695) ...
Summary
Part of #15382
This PR infers the return type
lambdaexpression asUnknown. In the future, it would be more useful to infer the expression type considering the surrounding context (#16696).This is done by adding the expression that represents the default value of the parameters as a standalone expression. Without this, it would create cycles as described in #16547. Both function and lambda expression's parameter defaults are added as standalone expression as we cannot differentiate between the two when doing the inference ininfer_parameter_definition.Test Plan
Update existing test cases from
@todoto the (verified) return type.