Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importlib error with create_api #85

Closed
bjarthur opened this issue Jul 18, 2023 · 2 comments
Closed

importlib error with create_api #85

bjarthur opened this issue Jul 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@bjarthur
Copy link

bjarthur commented Jul 18, 2023

the code below is straight out of the README. i think you just need to add from importlib import util to api.py

Python 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:17) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import portion
>>> class IntInterval(portion.AbstractDiscreteInterval):
...     _step = 1
... 
>>> D = portion.create_api(IntInterval)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/arthurb@hhmi.org/bin/mambaforge/envs/pyinterval/lib/python3.11/site-packages/portion/api.py", line 64, in create_api
    module = importlib.util.module_from_spec(
             ^^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'util'

i would tell you what version of portion i'm using, but __version__ is not defined:

>>> portion.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'portion' has no attribute '__version__'
@AlexandreDecan
Copy link
Owner

Hello,

Thanks for having reported this issue! It seems it's a "bad practice" I wrongly followed... :-) See https://bugs.python.org/issue41958

I'll try to release a fix ASAP, you're right, import importlib.util should do the trick. I don't know why this bug hasn't been catched by the tests....

@AlexandreDecan AlexandreDecan added the bug Something isn't working label Jul 18, 2023
@AlexandreDecan
Copy link
Owner

Ok, I got why the bug wasn't catched by our test: importlib.util was imported by another module (likely pytest or a dependency) making util available in importlib without an explicit import on our side.

I'll release a fix soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants