No project description provided
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for codemodimportfrom-0.7.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebc7c69191f50ca1d0a8900728f27381559a1d0e18ceca5c97b0135479b51a9e |
|
MD5 | e432dded60a4ac56dca08c44943474c7 |
|
BLAKE2b-256 | 6af31df81d1751d9d1447d18fac0cda5a659dc00c423d556df91817b0225bd47 |