Skip to content

pylint fails to resolve typing.Self from base classes #10807

@kdkavanagh

Description

@kdkavanagh

Very similar to #9159, pylint is unable to resolve typing.Self from base classes even when the method in question is not overridden (as it is in #9159)

Bug description

import typing


class A:
    def parent_meth(self) -> typing.Self:
        return self


class B(A):
    def meth(self) -> typing.Self:
        return super().parent_meth()

    def f2(self):
        pass


B().meth().f2()

Configuration

Command used

pylint test.py

Pylint output

************* Module test
test.py:4:0: R0903: Too few public methods (1/2) (too-few-public-methods)
test.py:17:0: E1101: Instance of 'A' has no 'f2' member (no-member)

Expected behavior

B().meth() should resolve to type B, thereby exposing f2()

Pylint version

$ pylint --version
pylint 4.0.2
astroid 4.0.2
Python 3.12.6 (main, Oct  9 2024, 11:19:43) [GCC 13.2.0]

OS / Environment

No response

Additional dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs astroid updateNeeds an astroid update (probably a release too) before being mergableNeeds investigation 🔬A bug or crash where it's not immediately obvious what is happenning

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions