Skip to content

Python: changing how imports are parsed, prefer J.Import#6730

Merged
greg-at-moderne merged 4 commits intomainfrom
greg-python-single-import-multiimport
Feb 13, 2026
Merged

Python: changing how imports are parsed, prefer J.Import#6730
greg-at-moderne merged 4 commits intomainfrom
greg-python-single-import-multiimport

Conversation

@greg-at-moderne
Copy link
Copy Markdown
Contributor

@greg-at-moderne greg-at-moderne commented Feb 13, 2026

What's changed?

Changing how imports are parsed for Python code.
Prefer J.Import (the same AST element as for Java and other languages) if possible - i.e. there's a single import.
Only use MultiImport if not possible.

What's your motivation?

Satisfy the objection of having as much LST re-use as reasonably possible.

greg-at-moderne and others added 3 commits February 13, 2026 09:14
Single `import foo` statements no longer get unnecessarily wrapped in
a `MultiImport` node. MultiImport is now only used when there are
multiple names (`import foo, bar`). Updated parser, printer, and
import recipes (add, remove, change) accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…port-multiimport

# Conflicts:
#	rewrite-python/rewrite/src/rewrite/python/_parser_visitor.py
@greg-at-moderne greg-at-moderne marked this pull request as ready for review February 13, 2026 09:44
@greg-at-moderne greg-at-moderne merged commit ad53660 into main Feb 13, 2026
1 check passed
@greg-at-moderne greg-at-moderne deleted the greg-python-single-import-multiimport branch February 13, 2026 09:45
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants