API Reference¶
flake8_dunder_all¶
A Flake8 plugin and pre-commit hook which checks to ensure modules have defined __all__.
Classes:
|
Enum of possible values for the |
|
A Flake8 plugin which checks to ensure modules have defined |
|
AST |
Functions:
|
Check the given filename for the presence of a |
-
class
AlphabeticalOptions(value)[source]¶ Bases:
EnumEnum of possible values for the
--dunder-all-alphabeticaloption.New in version 0.5.0.
-
class
Plugin(tree)[source]¶ Bases:
objectA Flake8 plugin which checks to ensure modules have defined
__all__.- Parameters
tree (
AST) – The abstract syntax tree (AST) to check.
Methods:
run()Run the plugin.
Attributes:
The plugin version
-
class
Visitor(use_endlineno=False)[source]¶ Bases:
NodeVisitorAST
NodeVisitorto check a module has defined__all__, and add one if it not.- Parameters
use_endlineno (
bool) – Flag to indicate whether the end_lineno functionality is available. This functionality is available on Python 3.8 and above, or when the tree has been passed throughflake8_dunder_all.utils.mark_text_ranges`(). DefaultFalse.
Changed in version 0.5.0: Added the
sorted_upper_first,sorted_lower_firstandall_linenoattributes.Attributes:
The line number where
__all__is defined.The value of
__all__.Flag to indicate a
__all__declaration has been found in the AST.The lineno of the last top-level or conditional import
List of functions and classed defined in the AST
Methods:
generic_visit(node)Called if no explicit visitor function exists for a node.
handle_def(node)Handles
def foo(): ...,async def foo(): ...andclass Foo: ....handle_import(node)Handles
import fooandfrom foo import bar.visit(node)Visit a node.
visit_AsyncFunctionDef(node)Visit
async def foo(): ....visit_ClassDef(node)Visit
class Foo: ....visit_FunctionDef(node)Visit
def foo(): ....visit_If(node)Visit an if statement and check if it’s for TYPE_CHECKING.
visit_Import(node)Visit
import foo.visit_ImportFrom(node)Visit
from foo import bar.visit_Try(node)Visit a Try statement.
-
generic_visit(node)¶ Called if no explicit visitor function exists for a node.
-
handle_def(node)[source]¶ Handles
def foo(): ...,async def foo(): ...andclass Foo: ....- Parameters
node (
Union[FunctionDef,AsyncFunctionDef,ClassDef]) – The node being visited.
-
handle_import(node)[source]¶ Handles
import fooandfrom foo import bar.- Parameters
node (
Union[Import,ImportFrom]) – The node being visited
-
visit(node)¶ Visit a node.
-
visit_AsyncFunctionDef(node)[source]¶ Visit
async def foo(): ....- Parameters
node (
AsyncFunctionDef) – The node being visited.
-
visit_ClassDef(node)[source]¶ Visit
class Foo: ....- Parameters
node (
ClassDef) – The node being visited.
-
visit_FunctionDef(node)[source]¶ Visit
def foo(): ....- Parameters
node (
FunctionDef) – The node being visited.
-
visit_If(node)[source]¶ Visit an if statement and check if it’s for TYPE_CHECKING.
- Parameters
node (
If) – The node being visited.
-
visit_ImportFrom(node)[source]¶ Visit
from foo import bar.- Parameters
node (
ImportFrom) – The node being visited
-
check_and_add_all(filename, quote_type='"', use_tuple=False)[source]¶ Check the given filename for the presence of a
__all__declaration, and add one if none is found.- Parameters
- Return type
- Returns
0if the file already contains a__all__declaration, has no function or class definitions, or has a `` # noqa: DALL000 ` comment.1If__all__is absent.4if an error was encountered when parsing the file.
Changed in version 0.2.0: Now returns
0and doesn’t add__all__if the file contains anoqa: DALL000comment.Changed in version 0.3.0: Added the
use_tupleargument.
flake8_dunder_all.__main__¶
Command-line entry point for flake8-dunder-all.
flake8_dunder_all.utils¶
General utility functions.
Functions:
|
Returns the linenumber of the start of the docstring for |
|
Recursively add the |
|
Tidy up the docstring for use as help text. |
-
mark_text_ranges(node, source)[source]¶ Recursively add the
end_linenoandend_col_offsetattributes to each child ofnodewhich already has the attributeslinenoandcol_offset.- Parameters
node (
AST) – An AST node created withast.parse().source (
str) – The corresponding source code for the node.