Usage

This library provides the Flake8 plugin flake8-dunder-all as well as the ensure-dunder-all script which adds __all__ to files that require it.

Flake8 codes

Code

Description

DALL000

Module lacks __all__.

DALL001

__all__ not sorted alphabetically

DALL002

__all__ not a list or tuple of strings.

For the DALL001 option there exists a configuration option (dunder-all-alphabetical) which controls the alphabetical grouping expected of __all__. The options are:

  • ignore__all__ should be sorted alphabetically ignoring case, e.g. ['bar', 'Baz', 'foo']

  • lower – group lowercase names first, then uppercase names, e.g. ['bar', 'foo', 'Baz']

  • upper – group uppercase names first, then uppercase names, e.g. ['Baz', 'Foo', 'bar']

If the dunder-all-alphabetical option is omitted the DALL001 check is disabled.

Changed in version 0.5.0: Added the DALL001 and DALL002 checks.

Note

In version 0.5.0 the entry point changed from DALL to DAL, due to changes in flake8 itself. However, the codes remain DALLXXX and should continue to work as normal.

ensure-dunder-all script

Given a list of Python source files, check each file defines __all__.

Exit codes:

  • 0: The file already contains a __all__ declaration or has no function or class definitions.

  • 1: A __all__ declaration was added to the file.

  • 4: A file could not be parsed due to a syntax error.

  • 5: Bitwise OR of 1 and 4.

ensure-dunder-all [OPTIONS] FILENAME

Options

--use-tuple

Use tuples instead of lists for __all__.

--quote-type <quote_type>

The type of quote to use.

Default

Arguments

FILENAME

Optional argument(s). Default None

pre-commit hooks

Using the Flake8 plugin as a pre-commit hook

This will only check for missing __all__ declarations but won’t add them.

See pre-commit for instructions

Sample .pre-commit-config.yaml:

- repo: https://github.com/pycqa/flake8
  rev: 3.8.4
  hooks:
  - id: flake8
    additional_dependencies:
    - flake8-dunder-all==0.5.0

Using the script as a pre-commit hook

This will add __all__ to files that require them and prevent the commit if any changes were made.

See pre-commit for instructions.

Sample .pre-commit-config.yaml:

- repo: https://github.com/python-formate/flake8-dunder-all
  rev: v0.5.0
  hooks:
  - id: ensure-dunder-all