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

Wrong type inferred - inference type cache is missing context #1828

Closed
kriek opened this issue Oct 10, 2022 · 3 comments · Fixed by #2158 or #2303
Closed

Wrong type inferred - inference type cache is missing context #1828

kriek opened this issue Oct 10, 2022 · 3 comments · Fixed by #2158 or #2303
Assignees
Labels
Milestone

Comments

@kriek
Copy link
Contributor

kriek commented Oct 10, 2022

Moving discussion started in pylint-dev/pylint#7464 to astroid repo.

Steps to reproduce

import astroid

result1, result2 = astroid.extract_node("""
class Base:
    def return_type(self):
        return type(self)()

class A(Base):
    def method(self):
        return self.return_type()

class B(Base):
    def method(self):
        return self.return_type()

A().method()  #@
B().method()  #@
""")

print(next(result1.infer()))
print(next(result2.infer()))

Current behavior

Instance of .A
Instance of .A

Expected behavior

Instance of .A
Instance of .B

Workaround

Modify inference_tip.py to disable cache in _inference_tip_cached function.

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

2.13.0-dev0

@kriek
Copy link
Contributor Author

kriek commented Oct 10, 2022

Timing the pylint evaluation of checkers/ folder from pylint repo, I don't see a big difference with and without (explicit raise KeyError inserted) the cache:
with:

real    0m57.994s
real    0m58.089s
real    0m57.446s
real    0m57.366s

without:

real    0m58.913s
real    0m58.693s
real    0m59.070s
real    0m58.799s

@DanielNoord
Copy link
Collaborator

Would you want to create a PR to remove it?

@kriek
Copy link
Contributor Author

kriek commented Oct 13, 2022

Yes, will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment