pylint-dev / pylint-dev/astroid
[2.0 bugs] A lookup in numpy infinitely recurses due to an interaction between a C extension and Python module
- 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**
---
test_numpy_crash fails (at least on Python 3) because, while trying to process an instance of ufunc, it looks up ufunc's type which has a declared module of numpy. It thus imports numpy's `__init__.py`, which contains `from .core import *`, and then tries to look up ufunc in that module. Eventually, it encounters a C extension, tries to analyze it using ast_from_object, and finds ufunc, only ufunc, being a type implemented in C, declares that its module is numpy, which sets off the infinite recursion because ast_from_object creates an ImportFrom node for it.
There are a number of possible fixes, I'm not immediately sure which would be best.
---
- Bitbucket: https://bitbucket.org/logilab/astroid/issue/262
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with test_numpy_crash and trace the lookup through ast_from_object, the ufunc type, and numpy's __init__.py as described in the report. Confirm the recursion under Python 3, then determine and document a fix that prevents the crash while preserving the expected C-extension analysis behavior; the regression test should pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100