API Reference¶
flake8_dunder_all
¶
A Flake8 plugin and pre-commit hook which checks to ensure modules have defined __all__
.
Classes:
|
A Flake8 plugin which checks to ensure modules have defined |
|
AST |
Functions:
|
Check the given filename for the presence of a |
-
class
Plugin
(tree)[source]¶ Bases:
object
A 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:
NodeVisitor
AST
NodeVisitor
to 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
.
Attributes:
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 foo
andfrom 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_Name
(node)Visit a variable.
-
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 foo
andfrom 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
0
if the file already contains a__all__
declaration, has no function or class definitions, or has a `` # noqa: DALL000 ` comment.1
If__all__
is absent.4
if an error was encountered when parsing the file.
Changed in version 0.2.0: Now returns
0
and doesn’t add__all__
if the file contains anoqa: DALL000
comment.Changed in version 0.3.0: Added the
use_tuple
argument.
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_lineno
andend_col_offset
attributes to each child ofnode
which already has the attributeslineno
andcol_offset
.- Parameters
node (
AST
) – An AST node created withast.parse()
.source (
str
) – The corresponding source code for the node.