Skip to main content

codemodimportfrom

CI

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)

Source distribution for codemodimportfrom 0.10.0
File Size Uploaded
codemodimportfrom-0.10.0.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for codemodimportfrom 0.10.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page