Skip to content

Overloaded class method with call to super() with typing.Self return type does not infer the right type #2852

@fgoudreault

Description

@fgoudreault

Here's a MWE:

from typing import Self

class C:
    @classmethod
    def from_nothing(cls) -> Self:
        return cls()

class D(C):
    @classmethod
    def from_nothing(cls) -> Self:
        return super().from_nothing()

class E(D):
    clsattr = 1

e = E.from_nothing()
print(e.clsattr, e.__class__.__name__)

pylint -E test.py:

************* Module test
test.py:17:6: E1101: Instance of 'C' has no 'clsattr' member (no-member)

while python test.py:

1 E

pylint --version:

pylint 3.3.9
astroid 3.3.11
Python 3.13.7 (tags/v3.13.7:bcee1c32211, Aug 18 2025, 10:05:53) [GCC 13.3.0]

I also notice the same pylint error is thrown even without classmethods but with regular methods (remove the @classmethod decorator and change cls -> self in the signature and return self in the C.from_nothing method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions