codemodimportfrom
Automatically update ImportFrom statements to "import modules, not objects".
Install
From within your project's virtual environment, install codemodimportfrom (as a dev dependency). e.g.
pip install codemodimportfrom
Usage
# Transform all ImportFrom statements in the file path/to/file.py
codemodimportfrom path/to/file.py
# Overwrite the file
codemodimportfrom path/to/file.py --write
# Transform ImportFrom statements for modules foo and bar only
codemodimportfrom path/to/file.py --module foo --module bar
# Allow object imports for typing.Optional and typing.Union
codemodimportfrom path/to/file.py --allow typing.Optional --allow typing.Union
# Allow all object imports from typing
codemodimportfrom path/to/file.py --allow "typing.*"
# Parse allow list from a .txt file (one line per allowed object import)
codemodimportfrom path/to/file.py --allow allow.txt
# Also transform module imports
# e.g. `from pydantic import dataclasses` becomes `import pydantic.dataclasses`
codemodimportfrom path/to/file.py --transform-module-imports
Caveats
- Not tested with much real world code, yet.
- Relative imports (
from . import foo) not implemented yet.
Metadata
Release files for codemodimportfrom 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| codemodimportfrom-0.10.0.tar.gz | 3.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| codemodimportfrom-0.10.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.4 kB
Release files / codemodimportfrom-0.10.0.tar.gz
| Download URL | codemodimportfrom-0.10.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b1b94d6137054af2d9a6dc1d1f51b37ef891da666588894bc5b99f6a6f8d40d
|
|
BLAKE2b-256 checksum How to use checksums |
336520e1e69a25d301b972eb66bc76a2106f0af0758972e5b8c5d0bf500c414d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.10.6 Darwin/22.6.0
|
Release files / codemodimportfrom-0.10.0-py3-none-any.whl
| Download URL | codemodimportfrom-0.10.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a7cebe740f692fc016297546af0d7dfd91ce25058079d5d90e892da75452ad10
|
|
BLAKE2b-256 checksum How to use checksums |
ee16ed23134dcaf1ef2fc2bf32d3da6d2b5ba14ca180ce1111e5c573d134c3a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.10.6 Darwin/22.6.0
|