pylint-dev / pylint-dev/astroid

One of the parents in chained attributes is sometimes wrong

Open
#272 0 comments 0 reactions 0 assignees View on GitHub
Bug 🪳
Dominant language
Python
Stars
582
Forks
357
Avg merge
1d 1h
Merged PRs (30d)
23

Description

Originally reported by: **Claudiu Popa (BitBucket: [PCManticore](http://bitbucket.org/PCManticore), GitHub: @PCManticore)**

---

Here's an example where the parent of an attribute in a chained attribute is wrong, pointing to a following attribute instead.

```
#!python

from astroid import parse
module = parse('''
class Tags:
def extend(self): return 42
class Removed:
def __init__(self):
self.tags = Tags()

removed = Removed()
removed.tags.extend()
''')
expr = module.body[-1]
callfunc = expr.value
print("callfunc", callfunc)
print("parent of callfunc", callfunc.parent)
print("func of callfunc", callfunc.func)
print("parent of func of callfunc", callfunc.func.parent)
print("expr of callfunc.func", callfunc.func.expr)
print("parent of expr of callfunc.func", callfunc.func.expr.parent) # This should be the Name, instead it is extend

from ast import parse
module = parse('''
class Tags:
def extend(self): return 42
class Removed:
def __init__(self):
self.tags = Tags()

removed = Removed()
removed.tags.extend()
''')
expr = module.body[-1]
callfunc = expr.value
print("callfunc", callfunc)
print("func of callfunc", callfunc.func.attr)
print("expr of callfunc", callfunc.func.value.attr)
print("expr of expr of callfunc", callfunc.func.value.value)
```

---
- Bitbucket: https://bitbucket.org/logilab/astroid/issue/272

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the chained-attribute example with astroid.parse and inspect the parent links for removed.tags.extend(), then compare them with the standard ast.parse structure shown in the issue. Trace the AST construction for chained attributes and verify that the parent of the final expression is the Name node rather than the following extend attribute.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.