Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect inference of self in methods defined in superclasses in unbound methods on a subclass #1008

Closed
nelfin opened this issue Jun 2, 2021 · 0 comments · Fixed by #1151
Labels

Comments

@nelfin
Copy link
Contributor

nelfin commented Jun 2, 2021

Steps to reproduce

import astroid
node = astroid.extract_node("""
class Base:
    def replace(self):
        return self

class Derived(Base):
    def method(self):
        return 123

this = Derived()
that = Derived.replace(this)
that
""")
inferred = next(node.infer())
inferred.getattr('method')

Current behavior

that is inferred as an instance of .Base not .Derived, causing this exception:

Traceback (most recent call last):
  File "astroid/bases.py", line 182, in getattr
    values = self._proxied.instance_attr(name, context)
  File "astroid/scoped_nodes.py", line 2433, in instance_attr
    raise exceptions.AttributeInferenceError(
astroid.exceptions.AttributeInferenceError: 'method' not found on <ClassDef.Base l.2 at 0x...>.

which leads to no-member warnings on pylint

Expected behavior

that is inferred as an instance of .Derived.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.5.7

Related issues

Appears to be the root-cause of pylint-dev/pylint#4377.
Ref pylint-dev/pylint#4487

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants