reassigning instance attribute causes it to become unbound
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
When overriding a variable in class, it becomes unbound.
**Code or Screenshots**
```python
class Foo:
def __init__(self):
self._val_bad = []
self._val_good = []
class Bar(Foo):
def __init__(self):
super().__init__()
# The line below causes `self._val_bad` to become unbound
# Commenting it eliminates the problem.
self._val_bad += [1]
self._val_good.extend([1])
def add(self):
return (
self._val_bad + [1], # _val_bad is reported as Unbound on this line
self._val_good + [2], # there is no error on this line
)
```
Output is:
```
scratch_198.py:17:13 - error: Operator "+" not supported for types "Unbound" and "list[int]" (reportOperatorIssue)
```
This issue appears to have been introduced in 1.1.394
Contributor guide
Research direction
Reproduce the diagnostic from the Python snippet in scratch_198.py, comparing the behavior introduced in Pyright 1.1.394 with the current behavior. Trace how the analyzer handles self._val_bad += [1] versus self._val_good.extend([1]); done means the valid _val_bad use in add no longer receives an Unbound error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100