-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Patch sys.path
on a per-file basis
#7357
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 2948717043
💛 - Coveralls |
from pylint.lint.expand_modules import get_python_path | ||
|
||
|
||
def get_python_path(filepath: str) -> str: |
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.
Should we cache this and/or fix_import_path
now that we launch the function a lot ?
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.
fix_import_path
is an iterator that changes sys.path
so I don't think we can cache that.
I'll cache get_python_path
.
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.
Oh never mind, I don't think get_python_path
ever gets called with the same argument, as it is part of the exploration of modules and we don't "explore the same module twice".
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 agree this looks promising. Some trivial cosmetic things.
@DanielNoord Have you tested this with namespace packages? Will it be a problem that |
Hmm, I'm not sure. Do you think it should? The |
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
I guess I was wondering if we should be doing less caching: if a module name that was cached by astroid's |
If anything I think this should reduce the occurrence of this issue (the original issue describes a similar issue actually). My thinking of this is as follows. The only thing I can think of that would be problematic is if package A imports package B before we lint package B and we determine during that import that B is namespace. However, I think that if we determine that it is namespace then it is likely correct: if you execute package A normally the interpreter also wouldn't magically patch package B onto your Not sure if I have explained myself enough here. Also, |
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit 008b348 |
Not really sure what to do with this PR. It's clear that creating the contextmanager for every file has significant performance impact, but I also can't think of a solution without doing so... The contextmanager itself also isn't that large so there isn't really anything to refactor to make it quicker to set up.. |
doc/whatsnew/<current release.rst>
.Type of Changes
Description
Closes #7339
I agree with @gcbirzan-plutoflume that the updated test outputs seem like they are actually beter. The change itself also makes sense imo, as Python also fixes
sys.path
once. See the issue for some further discussion.