Skip to content

fix import-no-init#816

Open
comhar wants to merge 1 commit into
mainfrom
fix/815-import-no-init-bug
Open

fix import-no-init#816
comhar wants to merge 1 commit into
mainfrom
fix/815-import-no-init-bug

Conversation

@comhar
Copy link
Copy Markdown
Contributor

@comhar comhar commented May 11, 2026

fixes #815

When running the xtra notebook locally I'm getting the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[75], line 1
----> 1 m = import_no_init('fastcore.basics')
      2 test_eq(m.__name__, 'fastcore.basics')
      3 assert hasattr(m, 'store_attr')
      4 

Cell In[74], line 7, in import_no_init(name)
      3     from importlib.machinery import PathFinder
      4     import importlib.util as iu
      5     parts = name.split('.')
      6     spec = PathFinder.find_spec(parts[0])
----> 7     path = Path(spec.origin)
      8     if len(parts)>1: path = path.parent.joinpath(*parts[1:]).with_suffix('.py')
      9     spec = iu.spec_from_file_location(name, path)
     10     mod = iu.module_from_spec(spec)

AttributeError: 'NoneType' object has no attribute 'origin'

On my machine fastcore is an editable install and PathFinder.find_spec can't find it.
iu.find_spec can find it.

This pr makes the following change.

spec = PathFinder.find_spec(parts[0])

to

spec = PathFinder.find_spec(parts[0]) or iu.find_spec(parts[0]).

@comhar comhar self-assigned this May 11, 2026
@comhar comhar added the bug Something isn't working label May 11, 2026
@comhar comhar requested a review from jph00 May 11, 2026 04:09
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

Successfully merging this pull request may close these issues.

import_no_init error

1 participant