Skip to content

Render leading dots for relative imports (PEP 328)#613

Open
mariopenterman wants to merge 1 commit into
zrax:masterfrom
mariopenterman:pr/relative-imports
Open

Render leading dots for relative imports (PEP 328)#613
mariopenterman wants to merge 1 commit into
zrax:masterfrom
mariopenterman:pr/relative-imports

Conversation

@mariopenterman

@mariopenterman mariopenterman commented Jun 22, 2026

Copy link
Copy Markdown

Relative imports lose their leading dots, producing invalid Python.

Before (current master)

from . import foo
from ..pkg.submod import qux

decompiles to:

from  import foo            # not valid Python
from pkg.submod import qux  # wrong: absolute

After this PR

from . import foo
from ..pkg.submod import qux

What it does

Captures the IMPORT_NAME level operand (the number of leading dots) instead of discarding it, stores it on ASTImport, and emits one . per level before the module name in both from ... import ... render paths.

A self-contained test is included; the full suite stays green.

Capture the IMPORT_NAME `level` operand (the number of leading dots) instead
of discarding it, store it on ASTImport, and emit one `.` per level before the
module name in both `from ... import ...` render paths. Restores relative
imports such as `from . import x`, `from ..pkg import y`.

Signed-off-by: Mario Penterman <mariopenterman@gmail.com>
@mariopenterman mariopenterman marked this pull request as ready for review June 22, 2026 22:17
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.

1 participant