Skip to content

type(self)() in inherited method inferred as parent class (E1101) #2329

@zuntrax

Description

@zuntrax

Steps to reproduce

  1. Create test.py:
#!/usr/bin/env python3

# pylint: disable=too-few-public-methods,missing-docstring

class Path:
    def __init__(self, name):
        self.name = name

    def __getitem__(self, name):
        return type(self)(f"{self.name}/{name}")

class Special(Path):
    def action(self):
        print(self.name)


def main():
    spam = Special("spam")
    eggs = spam["eggs"]
    print(type(eggs))
    eggs.action()


if __name__ == "__main__":
    main()
  1. Run pylint.
pylint test.py

Current behavior

************* Module test
test.py:21:4: E1101: Instance of 'Path' has no 'action' member (no-member)

------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 6.67/10, +0.00)

Expected behavior

No finding. eggs should have been inferred as instance of Special, not Path.

pylint --version output

pylint 2.0.0
astroid 2.0
Python 3.6.6 (default, Jun 27 2018, 13:11:40) 
[GCC 8.1.1 20180531]

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions