fix(python): don't emit too many leading dots for relative imports of nested files#4803
Merged
Merged
Conversation
caroott
force-pushed
the
fix/python-relative-import
branch
from
July 16, 2026 11:37
b530ca1 to
653b7cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4797
When a file nested inside a package imports from a sibling package two or more levels up, the generated relative import had one leading dot too many, e.g.
from ....relative_import_sibling.api import value # ImportError: attempted relative import beyond top-level packageinstead of the correct
from ...relative_import_sibling.api import valueThe parts of the resolved path are joined with
., so every..segment already contributes one dot through the separator. Since each segment was also mapped to a dot of its own, the result was only correct for single-level imports (the case in #4088/#4100). Now only the first..keeps its own dot. Single-level and same-package imports are unchanged.Verified with the minimal reproduction from the issue. The existing test suite only exercises single-level fable_modules imports (Thoth.Json). Covering the multi-level case would need a dependency with nested source folders, so I've left test placement to your judgement.