Skip to content

ImportFinder: Support find_spec interface #836

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

Merged
merged 1 commit into from
Jul 31, 2020
Merged

Conversation

tbabej
Copy link
Contributor

@tbabej tbabej commented Jul 31, 2020

The absence of ImportFinder wrapping the find_spec method (introduced in Python 3.4), which is a successor to now deprecated find_module [0] cause one of the finder classes to not find the namespace package, as it is only detectable using find_spec

Implements backwards-compatible logic to support find_spec if present in the Finder being wrapped.

Closes #835.

[0] https://docs.python.org/3/library/importlib.html#importlib.abc.MetaPathFinder.find_spec

@sebastinas sebastinas merged commit a453c02 into bpython:master Jul 31, 2020
@sebastinas
Copy link
Contributor

@tbabej Looks like that didn't cover all of it:

bpython version 0.20.dev10 on top of Python 3.8.5 /usr/bin/python3             
Traceback (most recent call last):                                             
  File "<input>", line 1, in <module>                                          
    from bpython.curtsiesfrontend._internal import _Helper                  
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load_unlocked                                                                                   
  File "<frozen importlib._bootstrap>", line 914, in _find_spec  
  File "/home/sebastian/development/bpython/bpython/curtsiesfrontend/repl.py", line 299, in find_spec
    spec.__loader__ = ImportLoader(self.watcher, spec.__loader__)              
AttributeError: 'ModuleSpec' object has no attribute '__loader__'              
Traceback (most recent call last):                                             
  File "<input>", line 1, in <module>                                          
    help = _Helper(_repl)            
NameError: name '_Helper' is not defined   

I've now changed it in afc28c3 to only replace __loader__ if defined and not None. Do you think that this makes sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bpython shell cannot import python namespace packages
2 participants