pylint-dev / pylint-dev/astroid
brain_builtin_inference does not account for the version differences in string methods or from __future__ import unicode_literals
- Dominant language
- Python
- Stars
- 582
- Forks
- 357
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
The `brain_builtin_inference` model for `str` methods has two long-standing gaps relative to what real Python 3 provides:
1. methods that were removed in Python 3 (e.g. `str.decode`) still infer to a value;
2. methods that exist in Python 3 (e.g. `str.isidentifier`) raise `InferenceError` instead of inferring the obvious result.
### Confirmed on astroid 4.2.0b3 (2026-05-25)
```python
import astroid
# str.decode does NOT exist on Py3 — but astroid happily infers '' for it
n = astroid.extract_node("' '.decode()")
print(repr(next(n.infer())))
# -> (value='') ❌
# str.isidentifier DOES exist on Py3 — astroid raises instead of inferring True
n = astroid.extract_node("'abc'.isidentifier()")
try:
print(next(n.infer()))
except Exception as e:
print(type(e).__name__, e)
# -> InferenceError: StopIteration raised without any error information. ❌
```
The expected behavior is:
- `' '.decode()` → no inference (the attribute does not exist on Py3 str), so subsequent attribute lookups should fail rather than succeed against a phantom `Const.str('')`.
- `'abc'.isidentifier()` → `Const.bool(True)`.
This is a brain-tip issue: the str method table in `brain_builtin_inference.py` needs to track which methods exist on the current target version (and either expose them with realistic return types, or omit them so attribute lookup correctly fails).
---
Originally reported in 2015 in the context of Python 2 vs Python 3 differences; Python 2 is gone, but the underlying brain-model asymmetry remains.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in brain_builtin_inference.py and inspect the str method table and how it handles the current Python target version. Compare the entries for decode and isidentifier with the issue’s expected inference behavior, then verify that removed methods no longer infer and supported methods return the expected constant.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100