-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Change find_module to find_spec for py37 compat #1563
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some problems with the implementation here, but I'm also not entirely sure I understand the problem. pkgutil.get_importer
says that it returns a finder, and the abstract base class importlib.Finder
has a find_module
as an abstract method. Can you provide a minimal example of some code that should work but doesn't because of this issue?
pkg_resources/__init__.py
Outdated
@@ -2098,8 +2098,13 @@ def _handle_ns(packageName, path_item): | |||
# capture warnings due to #1111 | |||
with warnings.catch_warnings(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this warning with importer.find_spec
, or does find_spec
not trigger the behavior from #1111?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried disabling this warning and did not see any ill effects. I do not know if this warning-kill needs to be kept, but I narrowed its scope in the latest commit.
pkg_resources/__init__.py
Outdated
try: | ||
loader = importer.find_spec(packageName).loader | ||
except: | ||
loader = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this try
/except
. Why is it done?
If it's because find_spec
raises an error instead of returning None
in the case that importer.find_module
would normally return None
, please narrow the exception catching to the specific exception raised in that instance. If it's just to avoid ever seeing an exception, drop this entirely - I'm not at all comfortable swallowing exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I narrowed the exceptions to AttributeError catches in the latest commit. This dodges a "find_spec" in dir(...)
check, which is an alternative if you'd prefer to avoid try/except entirely. Let me know if this addresses your concern.
The issue is most easily seen by stepping thru Ron89/thesaurus_query.vim#33, where The spirit of my patch is to allow both of these cases to work. I agree the |
@alhirzel I don't know if this is something that needs to be fixed here or in A simple minimal test case that should work but doesn't because of this issue, and contains no other distractions that may be causing the problem, is what we're looking for in terms of determining how to proceed. |
I think around Python 3.4, find_module (i.e. PEP 302) became depreciated by PEP 451. I think on some level, Vim's implementation may be clean on 451? Curious where you think the change should be. I will do more digging, including producing a |
@alhirzel I do not see anything in PEP 451 about In any case, if we do want to migrate off of using In any case, we'll need a minimal working example here anyway in order to write a failing test. I'm inclined to say that in this case, |
Eh, why are you asking me? |
@brammool I think because you made this commit on That said, I cant be sure it's a bug in |
My MNWE right now is
I dug into Vim's source and found My open questions right now:
|
No longer reproducible on new install of Arch Linux with same software versions. Something spooky must have been happening. closing PR |
@alhirzel Do you have any packages installed with 'namespace_packages.txt' files in your new install, to trigger the code path that calls find_module? If I install vim + python3 + python-setuptools in an 'archlinux/base' docker container, I see no problem with the command line vim --clean -c ':py3 import pkg_resources', however if I install e.g. python-matplotlib or python-protobuf the attempt to call vim.find_module then occurs and fails when 'import pkg_resources' is attempted by vim. |
The old install contained two packages in py3 with namespace_packages.txt included:
The new install had none. I installed |
latest commit addresses @pganssle comments |
@alhirzel Thank you for updating your PR. Please note that I am still not entirely sure if this is fixing a real problem, though I'm willing to be convinced that it is. I think the best way to get this accepted is to create a minimal example of how It also needs tests, but if the minimal example takes the form of a failing test, that's two birds with one stone. |
Hi, what is the state of this issue? I also encounter the problem when using vim together with python-3.7 and I can confirm what @fanovpn says. My question is, is this a bug in setuptools? Or is it a vim bug? |
@blastmaster The current state is this:
If you can do this, it will make the PR much easier to review. |
It looks like two people were super-close. @alhirzel said:
This isn't true. Vim moved a bit too fast and instead of deprecating @pganssle said:
If you look in PEP 451, it is actually deprecated:
So this is both Vim and setuptool's fault: setuptools is using a deprecated API (the lesser of the faults) and Vim removed a deprecated API (the greater of the faults). I think I can fix Vim's regression really easily: just move the bit about find_module so that it's not conditional on the python version. It looks like this commit prefers I may issue a PR on Vim in a bit, I need dinner... |
@joelfrederico Thanks for digging into that. I agree that if it's deprecated we should probably change it. This PR still definitely needs tests, we've been bitten before by seemingly simple changes to this kind of thing. Ideally we'd still have what I asked for above - some examples of edge cases that the new version solves - so that we can write tests around them to prevent regressions. I'm also worried that the semantics of this new mechanism seem different, so at least I'll need to understand how it works a lot better before merging any change. Separate PRs with tests (possibly extracted from real-life uses of |
I have a workaround! Before importing other modules, you can monkey-patch the vim module:
It's not ideal, but it works for simple cases. It probably messes up importing the vim module in some circumstances, and still needs to be fixed at any rate. |
@pganssle Thanks! Yeah, it's a completely new mechanism. Probably needs a completely new set of unit tests, not just one or two. I don't really know how setuptools is using the old mechanism. This is why things are deprecated IMHO: to give others (like setuptools) time to figure these problems out. Hopefully it can be done before |
I don't understand enough of the Python package ecosystem to issue a more insightful patch or write appropriate tests. It would be best if someone else took the wheel on this. |
This is a possible fix for python-mode#972. And it was based on pypa/setuptools#1563 (comment)
This is a possible fix for python-mode#972. And it was based on pypa/setuptools#1563 (comment)
Summary of changes
Change the call of
find_module
tofind_spec
.Attempts to fix Ron89/thesaurus_query.vim#33 and analogous issue tools-life/taskwiki#183, probably others brought about by vim/vim@79a494d5.
Pull Request Checklist