pylint-dev / pylint-dev/astroid
Unable to infer through a class constructor even with type hints
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 583
- Forks
- 357
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
Steps to reproduce
import astroid
func_node = astroid.extract_node("""
class Test:
def test():
return
class TestParent:
def __init__(self, test: Test):
self._test = Test() # type: Test
def test_class(self):
self._test.test() #@
test_parent = TestParent(Test())
""")
for inferred in func_node.func.infer():
if inferred is astroid.Uninferable:
assert()
func_node = astroid.extract_node("""
class Test:
def test():
return
class TestParent:
def __init__(self, test: Test):
self._test = test # type: Test
def test_class(self):
self._test.test() #@
test_parent = TestParent(Test())
""")
for inferred in func_node.func.infer():
if inferred is astroid.Uninferable:
assert()
Current behavior
astroid cannot infer when the object is passed into the class constructor. Only when it is created in the constructor,
Expected behavior
astroid is able to infer through the constructor.
I may just be doing something wrong, but I've been beating my head against this wall for a while now.
python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output
2.3.3
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the two astroid.extract_node reproductions and tracing the func_node.func.infer() calls, comparing the constructor-created and argument-passed cases. Done means the inference loop no longer encounters astroid.Uninferable when the typed Test object is passed through TestParent’s constructor.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100