Skip to main content

Module helpers

Module helpers 

Source

Structs§

AwaitVisitor
A Visitor that detects the presence of await expressions in the current scope.
NameFinder
A Visitor to collect all Expr::Name nodes in an AST.
RaiseStatementVisitor
A StatementVisitor that collects all raise statements in a function or method.
ReturnStatementVisitor
A Visitor that collects all return statements in a function or method.
StoredNameFinder
A Visitor to collect all stored Expr::Name nodes in an AST.

Enums§

Truthiness

Functions§

any_over_body
any_over_expr
Call func over every Expr in expr, returning true if any expression returns true..
any_over_interpolated_string_element
any_over_pattern
any_over_stmt
any_over_type_param
collect_import_from_member
Format the call path for a relative import.
comment_indentation_after
Determine the indentation level of an own-line comment, defined as the minimum indentation of all comments between the preceding node and the comment, including the comment itself. In other words, we don’t allow successive comments to ident further than any preceding comments.
contains_effect
Return true if the Expr contains an expression that appears to include a side-effect (like a function call).
extract_handled_exceptions
Extract the names of all handled exceptions.
format_import_from
Format the module reference name for a relative import.
format_import_from_member
Format the member reference name for a relative import.
from_relative_import
Format the call path for a relative import, or None if the relative import extends beyond the root module.
generate_comparison
in_nested_block
Check if a node is in a nested block.
is_assignment_to_a_dunder
Return true if the Stmt is an assignment to a dunder (like __all__).
is_compound_statement
Return true if the Stmt is a compound statement (as opposed to a simple statement).
is_const_false
Return true if an Expr is a literal False.
is_const_true
Return true if an Expr is a literal True.
is_constant
Return true if the Expr is a literal or tuple of literals.
is_constant_non_singleton
Return true if the Expr is a non-singleton constant.
is_docstring_stmt
Return true if a Stmt is a docstring.
is_dunder
is_empty_f_string
Returns true if the expression definitely resolves to the empty string, when used as an f-string expression.
is_mutable_iterable_initializer
Return true if the Expr is a mutable iterable initializer, like {} or [].
is_singleton
Return true if the Expr is a singleton (None, True, False, or ...).
is_sunder
Whether a name starts and ends with a single underscore.
is_unpacking_assignment
Check if a node represents an unpacking assignment.
map_callable
Given an Expr that can be callable or not (like a decorator, which could be used with or without explicit call syntax), return the underlying callable.
map_starred
Given an Expr that can be starred, return the underlying starred expression.
map_subscript
Given an Expr that can be a ExprSubscript or not (like an annotation that may be generic or not), return the underlying expr.
on_conditional_branch
Check if a node is part of a conditional branch.
pep_604_optional
Format the expression as a PEP 604-style optional.
pep_604_union
Format the expressions as a PEP 604-style union.
resolve_imported_module_path
Given an imported module (based on its relative import level and module name), return the fully-qualified module path.
to_module_path
Create a module path from a (package, path) pair.
typing_optional
Format the expression as a typing.Optional-style optional.
typing_union
Format the expressions as a typing.Union-style union.
uses_magic_variable_access
Return true if the body uses locals(), globals(), vars(), eval().