Skip to content

Attributes of types.FunctionType should be available on lambda functions #567

@AlexWaygood

Description

@AlexWaygood

Summary

ty currently emits a false-positive diagnostic on this snippet:

from typing import reveal_type

x = lambda y: y

# error[unresolved-attribute] Type `(y) -> Unknown` has no attribute `__code__`
reveal_type(x.__code__)  # revealed: Unknown

https://play.ty.dev/84a1b067-9670-4463-82ce-0fc025997c91

All lambda functions are instances of types.FunctionType, so all attributes available on types.FunctionType instances should also be available on lambdas.

Following astral-sh/ruff#18242 this is easy to fix: we just need to change this line so that it calls CallableType::function_like() rather than CallableType::single() (and add some tests).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedContributions especially welcomeruntime semanticsAccurate modeling of how Python's semantics work at runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions