Skip to content

mypy doesn't complain about wrong attribute access in unannotated method #1514

@The-Compiler

Description

@The-Compiler

With this code:

class Klass:

    def method1(self):
        print(self.attr)

    def method2(self) -> None:
        print(self.attr)

    def method3(self, arg: int):
        print(self.attr)

mypy complains about method2 and method3, but not method1:

x.py: note: In member "method2" of class "Klass":
x.py:7: error: "Klass" has no attribute "attr"
x.py: note: In member "method3" of class "Klass":
x.py:10: error: "Klass" has no attribute "attr"

Now looking at #1415 I thought adding --check-untyped-defs would help ("type check the interior of functions without type annotations"), but the output doesn't change with that argument. Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions