reportUnknownLambdaType.md
April 8, 2026 · View on GitHub
Overview
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.
Representative Issues
- #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.
Examples
Error:
transform = lambda x: x + 1 # Parameter 'x' has unknown type
Fix — add type annotations to the lambda:
from collections.abc import Callable
transform: Callable[[int], int] = lambda x: x + 1
Or use a named function with annotations:
def transform(x: int) -> int:
return x + 1
Common Fixes & Workarounds
- 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.
See Also
python.analysis.diagnosticSeverityOverrides— adjust or suppress this diagnosticpython.analysis.typeCheckingMode— controls which diagnostics are enabled by default