reportUnknownLambdaType is a diagnostic in Pylance and Pyright that warns when the type of a lambda function cannot be determined. This helps catch missing or ambiguous type information for lambdas, improving static analysis and code safety.
- #3347: Use keyword-only arguments in lambda functions when assigning them to protocols with specific argument requirements.
- #7039: Ensure that the
ownerargument in the__set_name__method can be used to infer the type of the descriptor.
Error:
transform = lambda x: x + 1 # Parameter 'x' has unknown typeFix — add type annotations to the lambda:
from collections.abc import Callable
transform: Callable[[int], int] = lambda x: x + 1Or use a named function with annotations:
def transform(x: int) -> int:
return x + 1- Add explicit type annotations to lambda parameters and return types where possible.
- Use protocols or type hints to clarify expected lambda signatures.
- Refactor code to use named functions with explicit types if needed.
- Review the Pyright configuration documentation for options to adjust or suppress this diagnostic if needed.
python.analysis.diagnosticSeverityOverrides— adjust or suppress this diagnosticpython.analysis.typeCheckingMode— controls which diagnostics are enabled by default