Skip to content

__new__ and subclassing is wrongly interpreted by mypy #13440

Closed
@socketpair

Description

@socketpair
class Base:
    def __new__(cls):
        return 42

    def get(self) -> str:
        return 'hello'

class Child(Base):
    pass


print(Child())
print(Child().get())

This code obviously will fail at runtime:

42
Traceback (most recent call last):
  File "/tmp/qwe2.py", line 13, in <module>
    print(Child().get())
AttributeError: 'int' object has no attribute 'get'

But MyPy sees nothing wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions