Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions docs/tutorial/supported-behaviors.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,81 @@ __all__.extend(["walk"])

---

## Star Import

When used with `--include-star-import`, unimport can refactor star imports into explicit
imports by detecting which names are actually used in the code.

**input**

```python
from os import *
from json import *

print(getcwd())
print(JSONEncoder)
```

**output**

```python
from os import getcwd
from json import JSONEncoder

print(getcwd())
print(JSONEncoder)
```

#### Duplicate Name Resolution

When multiple star imports export the same name, unimport deduplicates suggestions so
that only the last import provides each name (matching Python's shadowing semantics).
This produces correct output in a single pass.

**input**

```python
from _collections import *
from collections import *

print(defaultdict)
```

**output**

```python
from collections import defaultdict

print(defaultdict)
```

If the star imports partially overlap, each import keeps only its unique names:

**input**

```python
from collections import *
from _collections import *

print(Counter)
print(defaultdict)
```

**output**

```python
from collections import Counter
from _collections import defaultdict

print(Counter)
print(defaultdict)
```

Star import suggestions also respect explicit imports — if a name already has an
explicit import, star imports won't produce a duplicate for that name.

---

## Scope

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