Skip to content

Wrong inference maybe due to inference cache #669

Closed
PennyDreadfulMTG/Penny-Dreadful-Tools
#8447
@hippo91

Description

@hippo91

This bug has been found during the setup of the numpy brains.
Fixing it could improve our inference system for numpy functions.

The directory described hereafter reflects a similar structure inside the numpy sources.

Steps to reproduce

  1. Create a directory named bug_inf with the following structure:
$ tree bug_inf
bug_inf
├── core
│   ├── __init__.py
│   └── shape_base.py
├── __init__.py
└── lib
    ├── __init__.py
    └── shape_base.py
  1. bug_inf/core/__init__.py content is:
$ cat bug_inf/core/__init__.py 
from .shape_base import *
  1. bug_inf/core/shape_base.py content is:
$ cat bug_inf/core/shape_base.py 
def vstack():
    return 42
  1. bug_inf/__init__.py content is:
$ cat bug_inf/__init__.py 
from .core import *
from .lib import *
  1. bug_inf/lib/__init__.py content is:
$ cat bug_inf/lib/__init__.py 
from .shape_base import *
  1. bug_inf/lib/shape_base.py content is:
$ cat bug_inf/lib/shape_base.py 
from bug_inf.core import vstack
  1. Create a file bug_inf.py which content is:
from astroid import extract_node

SRC = """
from bug_inf import vstack
vstack()
"""

NODE = extract_node(SRC)
print(NODE.inferred())
  1. Run python3 bug_inf.py

Current behavior

 $ python3 bug_inf.py 
[<Const.int l.2 at 0x7f08471338d0>, Uninferable]

Expected behavior

 $ python3 bug_inf.py 
[<Const.int l.2 at 0x7f08471338d0>]

Astroid version

python3 -c "from astroid import __pkginfo__; print(__pkginfo__.version)"
2.3.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions