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

Fix python importing-error handling #3162

Closed
wants to merge 4 commits into from
Closed

Conversation

ichizok
Copy link
Contributor

@ichizok ichizok commented Jul 7, 2018

Problem

When importing python module, there is the case that the error occurred from module is incorrect.
(both +python and +python3)

Repro steps

/path/to/vim is Vim git repository.
The following step uses failing_import.py module in vim/src/testdir/pythonx.

$ cat /path/to/vim/src/testdir/pythonx/failing_import.py
raise ImportError

start Vim:

vim --clean

:set rtp+=/path/to/vim/src/testdir
:py import failing_import

then get ImportError:

Expected: ImportError() (empty message)
Actual: ImportError('No module named failing_import) (below)

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named failing_import

ImportError reports "No module named" though failing_import module exists.
That is, ImportError emitted from module inside is not propagated correctly.

Also python3.

Cause

vim.find_module does both finding and loading all intermediate packages and module, so ImportError in loading is treated as the error in finding module.

Solution

  • Do loading final module (does not include . in its name) in vim.load_module

@ichizok
Copy link
Contributor Author

ichizok commented Jul 7, 2018

Sorry, I made a mistake in repro steps:

:set rtp+=/path/to/vim/src/testdir/pythonx

correct: :set rtp+=/path/to/vim/src/testdir (drop /pythonx)

@codecov-io
Copy link

codecov-io commented Jul 7, 2018

Codecov Report

Merging #3162 into master will increase coverage by <.01%.
The diff coverage is 60.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3162      +/-   ##
==========================================
+ Coverage   76.55%   76.55%   +<.01%     
==========================================
  Files          93       93              
  Lines      136839   136857      +18     
==========================================
+ Hits       104752   104769      +17     
- Misses      32087    32088       +1
Impacted Files Coverage Δ
src/if_py_both.h 76.31% <60.52%> (-0.26%) ⬇️
src/os_unix.c 57.42% <0%> (-0.14%) ⬇️
src/window.c 81.9% <0%> (+0.03%) ⬆️
src/channel.c 83.15% <0%> (+0.03%) ⬆️
src/getchar.c 75.21% <0%> (+0.04%) ⬆️
src/normal.c 74.42% <0%> (+0.07%) ⬆️
src/ex_cmds2.c 82.72% <0%> (+0.09%) ⬆️
src/gui.c 49.58% <0%> (+0.2%) ⬆️
src/version.c 82.95% <0%> (+0.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fda95e7...df04338. Read the comment docs.

@brammool
Copy link
Contributor

Can you update this pull request for the latest changes?

@ichizok
Copy link
Contributor Author

ichizok commented Jul 22, 2018

Thank you, I updated this.

@eirnym
Copy link

eirnym commented Aug 2, 2018

The coverage dropped probably because of whitespace changes.

@brammool
Copy link
Contributor

brammool commented Aug 2, 2018 via email

@eirnym
Copy link

eirnym commented Aug 3, 2018

LGTM

@ichizok
Copy link
Contributor Author

ichizok commented Aug 3, 2018

@brammool This patch is ready to be merged.

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

Successfully merging this pull request may close these issues.

None yet

5 participants