import-future-annotations
Tool that checks presence of import from __future__ import annotations in python files and adds it if it's missing.
Installation
Requires Python >=3.8.
pip install import-future-annotations
Usage
import-future-annotations takes filenames as positional arguments.
Additional options:
--check-only: Don't modify files, only check. If script is applicable to any given file, the exit status code will be 1.--allow-empty: Add import to empty python files aswell.
As a pre-commit hook
See pre-commit for instructions
Sample .pre-commit-config.yaml:
- repo: https://github.com/mbroton/import-future-annotations
rev: v0.1.0
hooks:
- id: import-future-annotations
How does it work?
Files without docstrings
file.py before:
import os
import sys
...
Run pre-commit hook or execute command:
> import-future-annotations file.py
Adding annotations import to file.py
file.py after:
+ from __future__ import annotations
import os
import sys
Files with docstrings
file.py before:
"""
This is a module docstring.
"""
import os
import sys
...
Run pre-commit hook or execute command:
> import-future-annotations file.py
Adding annotations import to file.py
file.py after:
"""
This is a module docstring.
"""
+ from __future__ import annotations
import os
import sys
The import is placed after the module docstring (if present) or at the beginning of the file (if no docstring).
Files with syntax errors
Files containing syntax errors are automatically skipped with a warning message:
> import-future-annotations broken_file.py
Skipping broken_file.py: file contains syntax errors
Notes
- It won't add any blank lines, so I suggest to use/place it before
reorder_python_importshook or other hooks that may complain about it.
Metadata
Release files for import-future-annotations 1.0.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 | Provenance | Actions |
|---|---|---|---|---|
| import_future_annotations-1.0.0.tar.gz | 3.8 kB | Without provenance | Details for import_future_annotations-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| import_future_annotations-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for import_future_annotations-1.0.0-py3-none-any.whl |
Total release size: 8.5 kB
Release files / import_future_annotations-1.0.0.tar.gz
| Download URL | import_future_annotations-1.0.0.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42bcc591fcf419c8f6a27b0cd08d07b59be8ac764007f031cfd4dfbf4b7ee827
|
|
BLAKE2b-256 checksum How to use checksums |
6ca22b20b0c5f6f3e049746027063cf72c2eb684e0c675d6cda0aea2aca62d64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / import_future_annotations-1.0.0-py3-none-any.whl
| Download URL | import_future_annotations-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4265e4492f7f3a6881e654870d713560a59b33e696b14e6f52c39f2052ae23d6
|
|
BLAKE2b-256 checksum How to use checksums |
2b20867f6b4eb5c755830c3fa4c3976a443b6d71b202a4202612c6d6c4754adb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Security for import-future-annotations 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.