https://github.com/peter554/codemodimportfrom
https://github.com/peter554/codemodimportfrom
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/peter554/codemodimportfrom
- Owner: Peter554
- Created: 2023-10-15T14:35:59.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T05:37:31.000Z (almost 3 years ago)
- Last Synced: 2025-07-13T03:45:17.929Z (about 1 year ago)
- Language: Python
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# codemodimportfrom
[](https://github.com/Peter554/codemodimportfrom/actions/workflows/ci.yml)
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.
```sh
pip install codemodimportfrom
```
## Usage
```sh
# 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.