Skip to main content
Build Status Coverage Status Pypi Entry

A script to check for the imported __future__ modules to make it easier to have a consistent code base.

By default it requires and forbids all imports but it’s possible to have certain imports optional by ignoring both their requiring and forbidding error code. In the future it’s planned to have a “consistency” mode and that the default is having the import optional or required (not sure on that yet).

This module provides a plugin for flake8, the Python code checker.

Standalone script

The checker can be used directly:

$ python -m flake8-import --ignore FI10,FI11,FI12,FI13,FI15,FI5 some_file.py
some_file.py:1:1: FI14 __future__ import "unicode_literals" missing

Even though flake8 still uses optparse this script in standalone mode is using argparse.

Plugin for Flake8

When both flake8 and flake8-future-imports are installed, the plugin is available in flake8:

$ flake8 --version
5.0.3 (flake8-future-import: 0.4.6, mccabe: 0.7.0, pycodestyle: 2.9.0, pyflakes: 2.5.0) CPython 3.9.5 on Windows

By default the plugin will check for all the future imports but with --ignore it’s possible to define which imports from __future__ are optional, required or forbidden. It will emit a warning if necessary imports are missing:

$ flake8 --ignore FI10,FI11,FI12,FI13,FI15,FI5 some_file.py
...
some_file.py:1:1: FI14 __future__ import "unicode_literals" missing

Parameters

This module adds one parameter:

  • --require-code: Doesn’t complain on files which only contain comments or strings (and by extension docstrings). Corresponds to require-code = True in the tox.ini.

  • --min-version: Define the minimum version supported by the project. Any features already mandatory or not available won’t cause a warning when they are missing. Corresponds to min-version = … in the tox.ini.

The stand alone version also mimics flake8’s ignore parameter.

Error codes

This plugin is using the following error codes:

FI10

__future__ import “division” missing

FI11

__future__ import “absolute_import” missing

FI12

__future__ import “with_statement” missing

FI13

__future__ import “print_function” missing

FI14

__future__ import “unicode_literals” missing

FI15

__future__ import “generator_stop” missing

FI16

__future__ import “nested_scopes” missing

FI17

__future__ import “generators” missing

FI18

__future__ import “annotations” missing

FI50

__future__ import “division” present

FI51

__future__ import “absolute_import” present

FI52

__future__ import “with_statement” present

FI53

__future__ import “print_function” present

FI54

__future__ import “unicode_literals” present

FI55

__future__ import “generator_stop” present

FI56

__future__ import “nested_scopes” present

FI57

__future__ import “generators” present

FI58

__future__ import “annotations” present

FI90

__future__ import does not exist

For a sensible usage, for each import either or both error code need to be ignored as it will otherwise always complain either because it’s present or because it is not. The corresponding other error code can be determined by adding or subtracting 40.

  • Ignoring the lower one will forbid the import

  • Ignoring the higher one will require the import

  • Ignoring both will make the import optional

The plugin is always producing errors about missing and present imports and flake8 actually does ignore then the codes accordingly. So the plugin does not know that an import is allowed and forbidden at the same time and thus cannot skip reporting those imports.

Changes

0.4.7 - 2022-08-02

  • Fix error reported with flake8 version 5

0.4.6 - 2019-08-04

  • Add new annotations feature.

0.4.5 - 2018-04-15

  • Support pip version 10 in the tests.

  • Add LICENSE and test_flake8_future_import.py to the source distribution.

0.4.4 - 2018-01-05

  • Add Flake8 framework classifier.

0.4.3 - 2016-07-01

  • When using Flake8 version 2, it wasn’t correctly looking for the options in the tox.ini file. This is restoring the old behaviour there.

0.4.2 - 2016-07-01

  • Support flake8 version 3’s new config option interface

  • Do not increase offset by one in the standalone variant, like flake8 does with version 3

0.4.1 - 2016-05-30

  • Do not ignore imports which are present and have been added after the minimum version

  • Ignore imports which became mandatory with the minimum version

0.4.0 - 2016-05-30

  • Add two older future imports

  • Issue an error when a future import does not exist

  • Define which is the oldest Python version to be supported so that already mandatory features can be ignored and not yet supported features default to forbidden (ignoring the lower error code).

  • Use return code of 1 if errors occurred

0.3.2 - 2015-10-18

  • Prevent errors when using unknown future imports

  • Test several examples for bad future imports from the Python library

  • Fixed the README to use present for the higher codes

0.3.1 - 2015-09-07

  • Support setting --require-code in the tox.ini

0.3.0 - 2015-09-07

  • Using a different error code namespace (FIXX)

  • Add error codes returned when an import is present

  • Removed nested_scopes and generators from the available list

  • Skip files which only contains comments and strings

0.2.1 - 2015-08-10

  • Fixed the module and URL in setup.py

  • Fixed the name in the script itself

0.2 - 2015-08-10

  • Instead of parameters it’s now using error codes to define which futures are missing. This is removing the ability to forbid a future for now.

0.1 - 2015-08-08

  • First release

Metadata

Release files for flake8-future-import 0.4.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-future-import 0.4.7
File Size Uploaded Provenance Actions
flake8-future-import-0.4.7.tar.gz 11.7 kB Without provenance Details for flake8-future-import-0.4.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flake8-future-import 0.4.7
File Interpreter ABI Platform Actions
flake8_future_import-0.4.7-py2.py3-none-any.whl Python 2, Python 3 none any Details for flake8_future_import-0.4.7-py2.py3-none-any.whl

Total release size: 19.6 kB

Release files / flake8-future-import-0.4.7.tar.gz

Download URL flake8-future-import-0.4.7.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ed826cca28fd4b55c486d69c4bfb32e9a052efc66714bf22bf471f50ecf8e0de
BLAKE2b-256 checksum
How to use checksums
2faa61c97012ce14d69730ced33bbc19837a86dbb5c400acb9163d5f9afbfca2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.5

Release files / flake8_future_import-0.4.7-py2.py3-none-any.whl

Download URL flake8_future_import-0.4.7-py2.py3-none-any.whl
Size 7.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7ecb1b89f5e026afb0cfdb8642d150bf56efbb6fb86a713ea4568398142f47ae
BLAKE2b-256 checksum
How to use checksums
70ad3a88ed602f05cb91935a605fe92545e78637fe11fc06f5ba99fb5107967a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.5

Security for flake8-future-import 0.4.7

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.

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