Skip to content

Fix VimPathFinder.find_spec (Python 3.4+) #297

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 2 commits into from
May 6, 2018

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Jan 24, 2018

The fix is similar to what VimModuleLoader.find_module does already.

# path appears to be the module then, and calling find_spec with it
# fails.
try:
return sys.modules[fullname].__spec__
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__spec__ might be None here.. seen when using jedi-vim, which apparently also comes here.

Need to investigate..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidhalter
Any idea maybe?
Maybe AttributeError could be handled like KeyError, but it would be good to know what is going on.

I do not have the details anymore, but am using this branch again now (to fix reload(jedi_vim) in Neovim).

@blueyed
Copy link
Contributor Author

blueyed commented May 5, 2018

While #297 (comment) is not really clear, I think this PR is better than the current situation, where reload() does not work at all:

:py3 from importlib import reload; reload(jedi_vim) results in:

Error detected while processing function provider#python3#Call:
line   18:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.6/importlib/__init__.py", line 165, in reload
    spec = module.__spec__ = _bootstrap._find_spec(name, pkgpath, target)
  File "<frozen importlib._bootstrap>", line 894, in _find_spec          
  File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1129, in _get_spec
  File "…/neovim-python-client/neovim/plugin/script_host.py", line 247, in find_spec
    return PathFinder.find_spec(fullname, path or _get_paths(), target)
  File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1123, in _get_spec
TypeError: 'module' object is not iterable                              

find_spec gets called with the following with reload:

find_spec: fullname='jedi_vim', path=<module 'jedi_vim' from '/home/user/.vim/plugged/jedi-vim/pythonx/jedi_vim.py'>, target=None

@blueyed blueyed changed the title Fix VimPathFinder.find_spec for reloading a module Fix VimPathFinder.find_spec (Python 3.4+) May 5, 2018
@blueyed
Copy link
Contributor Author

blueyed commented May 5, 2018

Found the issue: it was not using the correct interface (path is only used with meta path finders!).

@justinmk
Copy link
Member

justinmk commented May 6, 2018

LGTM. The flake8 failure happens on master, seems like a flake8 bug.

flake8 version:

checkqa installed: flake8==3.5.0

Did a web search but didn't find much.

@justinmk justinmk merged commit b9eff51 into neovim:master May 6, 2018
@blueyed blueyed deleted the fix-reload branch May 6, 2018 16:41
@blueyed
Copy link
Contributor Author

blueyed commented May 6, 2018

@justinmk

The flake8 failure happens on master, seems like a flake8 bug.

Could you reproduce it locally?
tox -e checkqa works for me.

@justinmk
Copy link
Member

justinmk commented May 6, 2018

@blueyed yes, in a virtualenv:

$ ./venv/bin/pip3 install .

$ ./venv/bin/python --version
Python 3.5.2
$ ./venv/bin/tox --version
3.0.0 imported from /home/vagrant/python-client/venv/lib/python3.5/site-packages/tox/__init__.py
$ ./venv/bin/flake8 --version
3.5.0 (mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 3.5.2 on Linux

$ 


TOXENV=checkqa ./venv/bin/tox
...
AttributeError: 'Attribute' object has no attribute 'id'
ERROR: InvocationError for command '/home/vagrant/python-client/.tox/checkqa/bin/flake8 neovim' (exited with code 1)

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.

2 participants