Skip to main content

A flake8 plugin that helps you write tidier imports.

Project description

Flake8 Tidy Imports

https://img.shields.io/pypi/v/flake8-tidy-imports.svg https://img.shields.io/travis/adamchainz/flake8-tidy-imports.svg

A flake8 plugin that helps you write tidier imports.

  • Free software: ISC license

Installation

Install from pip with:

pip install flake8-tidy-imports

It will then automatically be run as part of flake8; you can check it has been picked up with:

$ flake8 --version
2.4.1 (pep8: 1.7.0, pyflakes: 0.8.1, flake8-tidy-imports: 1.0.0, mccabe: 0.3.1) CPython 2.7.11 on Darwin

Options

banned-modules

An equals-delimited map of modules to messages to include about them, in rule I201 (see below). Whilst it can be passed on the commandline, it’s much easier to configure it in your config file, such as setup.cfg - for example:

[flake8]
banned-modules = mock = Use unittest.mock!
                 urlparse = Use six.moves.urllib.parse!

Rules

Currently this plugin has two rules.

I200: Unnecessary import alias

Complains about unnecessary import aliasing of three forms:

  • import foo as foo -> import foo

  • import foo.bar as bar -> from foo import bar

  • from foo import bar as bar -> from foo import bar

The message includes the suggested rewrite (which may not be correct at current), for example:

$ flake8 file.py
file.py:1:1: I200 Unnecessary import alias - rewrite as 'from foo import bar'.

I201: Banned module ‘foo’ imported

Complains about importing of banned modules. This might be useful when refactoring code, for example when moving from Python 2 to 3. By default there are no modules banned - you should configure them with banned-modules as described above in ‘Options’.

The message includes a user-defined part that comes from the configuration. For example:

$ flake8 file.py
file.py:1:1: I201 Banned module 'mock' imported - Use unittest.mock instead.

History

Pending Release

  • New release notes here

1.0.1 (2016-07-01)

  • I201 rule that allows you to configure complaining about certain modules being imported, e.g. if you are moving from Python 2 to 3 you could stop urlparse being imported in favour of six.moves.urllib.parse.

1.0.0 (2016-01-23)

  • First release on PyPI.

  • I200 rule that complains about unnecessary import aliasing, e.g. from foo import bar as bar.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-tidy-imports-1.0.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

flake8_tidy_imports-1.0.1-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file flake8-tidy-imports-1.0.1.tar.gz.

File metadata

File hashes

Hashes for flake8-tidy-imports-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1466ba57904e051d5dacdb34100b25058e66dc6d0ae03c555d317a3bb3eed08a
MD5 a7f297bae715301a9702cc45b4c50eda
BLAKE2b-256 7a420137ce0f0ddb7fe2afbc76868969db451c5291d2dd54044498046eae1aeb

See more details on using hashes here.

File details

Details for the file flake8_tidy_imports-1.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_tidy_imports-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 eeaad7507d0722216f197872d12e5d5af82e305a807a36d977718bb1d39fa6f6
MD5 9e05dc6c603f644815a34a210bdfc7a1
BLAKE2b-256 ee082906a328411d4c8e91ac7ba1000c14dc882fea0d4be982620bbea3a5655f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page