mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[ty] Treat lambda functions as instances of types.FunctionType (#18431)
This commit is contained in:
parent
47698883ae
commit
f379eb6e62
2 changed files with 20 additions and 1 deletions
|
@ -115,3 +115,22 @@ a5: Callable[[], None] = lambda x: None
|
|||
# error: [invalid-assignment]
|
||||
a6: Callable[[int], None] = lambda: None
|
||||
```
|
||||
|
||||
## Function-like behavior of lambdas
|
||||
|
||||
All `lambda` functions are instances of `types.FunctionType` and should have access to the same set
|
||||
of attributes.
|
||||
|
||||
```py
|
||||
x = lambda y: y
|
||||
|
||||
reveal_type(x.__code__) # revealed: CodeType
|
||||
reveal_type(x.__name__) # revealed: str
|
||||
reveal_type(x.__defaults__) # revealed: tuple[Any, ...] | None
|
||||
reveal_type(x.__annotations__) # revealed: dict[str, @Todo(Support for `typing.TypeAlias`)]
|
||||
reveal_type(x.__dict__) # revealed: dict[str, Any]
|
||||
reveal_type(x.__doc__) # revealed: str | None
|
||||
reveal_type(x.__kwdefaults__) # revealed: dict[str, Any] | None
|
||||
reveal_type(x.__module__) # revealed: str
|
||||
reveal_type(x.__qualname__) # revealed: str
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue