Skip to content

Support __getattr__ #520

Closed
Closed
@JukkaL

Description

@JukkaL

Support overloading attribute access by defining a __getattr__ method. If a class has a __getattr__ method, mypy should let programs access any attributes, and the type would be the return type of __getattr__. Example:

class A:
    def __getattr__(self, name: str) -> int: return 2
a = A()
print(a.foobar)   # okay, type is int

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions