pylint-dev / pylint-dev/astroid
Inference for objects with C accelerators and pure-Python equivalents typically returns Uninferable
- Dominant language
- Python
- Stars
- 582
- Forks
- 357
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
Originally reported by: **BitBucket: [ceridwenv](http://bitbucket.org/ceridwenv), GitHub: @ceridwen**
---
For instance, look at lazy_object_proxy.
``` python
>>> m = parse('import lazy_object_proxy; lazy_object_proxy.Proxy(lambda: None)')
>>> proxy_call = m.body[1].value
>>> proxy_call
>>> next(proxy_call.infer())
Uninferable
```
This happens because in lazy_object_proxy's `__init__.py`, the C accelerator is tried first. This is a typical pattern.
``` python
try:
from .cext import Proxy
from .cext import identity
except ImportError:
from .slots import Proxy
```
Then, the module importing subsystem ends up building an empty module for lazy_object_proxy.cext.
``` python
(Pdb) self.astroid_cache['lazy_object_proxy.cext'].print_tree()
Module(
name='lazy_object_proxy.cext',
doc=None,
package=False,
pure_python=True,
source_code=b'',
source_file='',
body=[])
```
This happens even on PyPy and Jython, so the presence of any C accelerator will break inference for the pure Python equivalent.
---
- Bitbucket: https://bitbucket.org/logilab/astroid/issue/263
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the example with lazy_object_proxy and inspect the module importing subsystem, especially the empty lazy_object_proxy.cext module in astroid_cache. Compare the __init__.py fallback from cext.Proxy to slots.Proxy; done means inference resolves the pure-Python equivalent instead of returning Uninferable when a C accelerator is unavailable.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100