-
-
Notifications
You must be signed in to change notification settings - Fork 280
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 regression with import resolver #1211
Conversation
for more information, see https://pre-commit.ci
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.
Amazing 🎉 This is going to remove so much false positives.
@DanielNoord I think you accidentally committed the first commit to The changes here seem to work, I'll take a closer look next. |
We might want to protect this branch if this happen more often, but this is very convenient to be able to push directly when releasing. |
Maybe something like this: https://github.com/pre-commit/pre-commit-hooks#no-commit-to-branch ? - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: no-commit-to-branch
args:
- --branch=main That would only be a pre-commit check, thus it could be skipped by using -- |
I think it was because I pressed 'sync' in VS Code for the 'pylint' branch which included the tests. Because I had opened a file from 'astroid' in that workplace previously it opened the local 'astroid' repo, which was based on main. Even after closing said file, the repo remains in the source control tab. |
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.
Did some last tests: The change works as expected. Thanks @DanielNoord 🚀
Can you add a small changelog entry? The line from the pylint PR should work (together with closes ...).
Interestingly, I wasn't able to make the test you added fail for astroid
, only for pylint
. Maybe you have an idea, if not don't know if it makes sense to add something that doesn't test anything.
I think we might want to do some tests for some of the other issues reported with namespace packages, as this commit might help bring those closer to a solution.
Will do this this afternoon and merge afterwards!
I have no idea. @Pierre-Sassoulas and I struggled to come up with good tests in #1186 and he finally merged it with the tests I included. I also don't know how we should test this in |
In that case, maybe it's not worth keeping this one in |
Usually I would prefer tests, but tbh I couldn't come up with one that worked. What might work would be a strict unit test just for Don't know if @Pierre-Sassoulas has any ideas.
I would say we should remove the test added with this PR. I haven't tested it, but the other ones might actually work. There we needed to test that -- |
Maybe it's the time to put "real world" test in place where we run pylint on open-source python code available online. numpy, pandas, requests, colorama, botocore, setuptools, ... there's a lot of choices and probably some variety and some namespace packages too. We could run those only for "risky" changes. Real world examples are hard to do well. black is doing something similar I don't remember how they call it. It would reduce the risk we take during release greatly. Plus there are already some slow tests that we're not running in the CI for pylint (acceptance). |
pylint-dev/pylint#4413 😄 What I'm trying to say: I would love it if we could automate it, just not sure it's actually possible / useful for our development cycle. |
However, this particular issue depends on file being present in the directory of the checked module. Which I think can't be emulated in such a simple function as these two. |
Ha, very true. But we can check that pylint is "not crashing". And I think we could check for the presence of error. There's a very slim possibility that there is a real error in a release of those very big libraries but I would bet on a pylint false positive or regression every time. And in particular if suddenly there's a ton of |
Steps
Description
This fixes the regression reported in pylint-dev/pylint#5131
Basically the previous iteration of the import resolver wrongly assumed that the current path was also the directory of the module which was checked for existence of
__init__.py
. We now check whether thenodes.Module
has a path and then check the directory of that path for a__init__.py
.The check for existence of
self.path
is becausetest_relative_to_absolute_name
intests/unittest_scoped_nodes.py
failed. I wonder if it is actually relevant for any real examples as I think anodes.Module
should always have apath
, but I think that is something for another time.While I was working on this I also added basic typing to the function in the new format.
Type of Changes
Related Issue
Ref. #1186, #1200, pylint-dev/pylint#5059