Skip to content

Commit f6d87d8

Browse files
hakancelikdevclaude
andcommitted
Add star import dedup behavior to supported-behaviors docs
Document how --include-star-import works with multiple star imports: - Basic star import refactoring (star to explicit imports) - Duplicate name resolution across multiple star imports (last import wins, matching Python's shadowing semantics) - Partial overlap handling (each import keeps unique names) - Explicit import awareness (no duplicates with existing imports) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a702ffb commit f6d87d8

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

docs/tutorial/supported-behaviors.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,81 @@ __all__.extend(["walk"])
9090

9191
---
9292

93+
## Star Import
94+
95+
When used with `--include-star-import`, unimport can refactor star imports into explicit
96+
imports by detecting which names are actually used in the code.
97+
98+
**input**
99+
100+
```python
101+
from os import *
102+
from json import *
103+
104+
print(getcwd())
105+
print(JSONEncoder)
106+
```
107+
108+
**output**
109+
110+
```python
111+
from os import getcwd
112+
from json import JSONEncoder
113+
114+
print(getcwd())
115+
print(JSONEncoder)
116+
```
117+
118+
#### Duplicate Name Resolution
119+
120+
When multiple star imports export the same name, unimport deduplicates suggestions so
121+
that only the last import provides each name (matching Python's shadowing semantics).
122+
This produces correct output in a single pass.
123+
124+
**input**
125+
126+
```python
127+
from _collections import *
128+
from collections import *
129+
130+
print(defaultdict)
131+
```
132+
133+
**output**
134+
135+
```python
136+
from collections import defaultdict
137+
138+
print(defaultdict)
139+
```
140+
141+
If the star imports partially overlap, each import keeps only its unique names:
142+
143+
**input**
144+
145+
```python
146+
from collections import *
147+
from _collections import *
148+
149+
print(Counter)
150+
print(defaultdict)
151+
```
152+
153+
**output**
154+
155+
```python
156+
from collections import Counter
157+
from _collections import defaultdict
158+
159+
print(Counter)
160+
print(defaultdict)
161+
```
162+
163+
Star import suggestions also respect explicit imports — if a name already has an
164+
explicit import, star imports won't produce a duplicate for that name.
165+
166+
---
167+
93168
## Scope
94169

95170
Unimport tries to better understand whether the import is unused by performing scope

0 commit comments

Comments
 (0)