-
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
[red-knot] Fix relative imports in src.root
#15990
Conversation
d3dd1ee
to
8f08246
Compare
from crates.ruff_linter.resources.test.cpython.Lib.typing import reveal_type | ||
|
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.
not sure what this is doing here :P
from crates.ruff_linter.resources.test.cpython.Lib.typing import reveal_type |
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.
lol, Pycharm tried to be clever
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.
Thanks for catching this
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.
Nice -- well diagnosed!
8f08246
to
a1e265d
Compare
I think this change is not correct? Python does not actually allow this at runtime. It seems like a bug in pyright if it allows it. If I create these two files:
x = 1
from .lib import x The result of The tomllib modules actually exist within a |
Hmm true. I'll revert tomorrow and add an explicit test for it. I didn't consider testing it, I trusted Pyright but it seems I shouldn't have. |
…e root of a search path (#16001) ## Summary This PR reverts the behavior changes from #15990 But it isn't just a revert, it also: * Adds a test covering this specific behavior * Preserves the improvement to use `saturating_sub` in the package case to avoid overflows in the case of invalid syntax * Use `ancestors` instead of a `for` loop ## Test Plan Added test
Summary
Fixes #15989
Red Knot failed to resolve relative imports if the importing module is located at a search path root.
The issue was that the module resolver returned an
Err(TooManyDots)
as soon as the parent of the current module isNone
(which is the case for a module at the search path root).However, this is incorrect if there's a
tail
(a module name).Test Plan
Added mdtests