Skip to content

Latest commit

 

History

History
43 lines (28 loc) · 1.77 KB

File metadata and controls

43 lines (28 loc) · 1.77 KB

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 owner argument 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

  1. Add explicit type annotations to lambda parameters and return types where possible.
  2. Use protocols or type hints to clarify expected lambda signatures.
  3. Refactor code to use named functions with explicit types if needed.
  4. Review the Pyright configuration documentation for options to adjust or suppress this diagnostic if needed.

See Also