-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Bug description
When using PriceCollector.collect(), an AttributeError: module 'utils' has no attribute 'collect_vendors' can occur if the user's project also contains a file named utils.py in the root directory (i.e., the current working directory when running a script or notebook).
This happens because chemprice/chemprice.py (and potentially other internal modules) uses an absolute import import utils. This can cause Python to import the user's utils.py instead of the chemprice package's own chemprice/utils.py file, which contains the collect_vendors function.
To Reproduce
Steps to reproduce the behavior:
- Create a Python project.
- Install
chemprice. - Create a file named
utils.pyin the root of the project (it can be empty or contain any code). - In a script or notebook in the project root, try to use
PriceCollector().collect(["CCO"]). - See error:
AttributeError: module 'utils' has no attribute 'collect_vendors'
Expected behavior
chemprice should always use its internal utils.py module, regardless of whether a utils.py file exists in the user's project directory.
Suggested Solution
Modify the import statement in chemprice/chemprice.py (and any other internal modules that import utils) from:
import utils
to a relative import:
from . import utils
This will ensure that the chemprice package always loads its own utils module.
Environment (example):
- Python version: 3.11
- chemprice version: 1.1.0
- OS: macOS