Skip to content

fix(python): don't emit too many leading dots for relative imports of nested files#4803

Merged
dbrattli merged 1 commit into
fable-compiler:mainfrom
caroott:fix/python-relative-import
Jul 17, 2026
Merged

fix(python): don't emit too many leading dots for relative imports of nested files#4803
dbrattli merged 1 commit into
fable-compiler:mainfrom
caroott:fix/python-relative-import

Conversation

@caroott

@caroott caroott commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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 package
instead of the correct
from ...relative_import_sibling.api import value

The 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.

@caroott
caroott force-pushed the fix/python-relative-import branch from b530ca1 to 653b7cd Compare July 16, 2026 11:37

@dbrattli dbrattli left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing!

@dbrattli
dbrattli merged commit 9fa4924 into fable-compiler:main Jul 17, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Nested Fable package imports contain too many leading dots

2 participants