module documentation

Undocumented

Class ConsiderUsingWithStack Stack for objects that may potentially trigger a R1732 message if they are not used in a ``with`` block later on.
Constant BUILTIN_EXIT_FUNCS Undocumented
Constant CALLS_RETURNING_CONTEXT_MANAGERS Undocumented
Constant CALLS_THAT_COULD_BE_REPLACED_BY_WITH Undocumented
Constant KNOWN_INFINITE_ITERATORS Undocumented
Type Alias NodesWithNestedBlocks Undocumented
Function _except_statement_is_always_returning Detect if all except statements return.
Function _if_statement_is_always_returning Undocumented
Function _is_a_return_statement Undocumented
Function _is_inside_context_manager Undocumented
Function _is_part_of_assignment_target Check whether use of a variable is happening as part of the left-hand side of an assignment.
Function _is_part_of_with_items Checks if one of the node's parents is a ``nodes.With`` node and that the node itself is located somewhere under its ``items``.
Function _is_trailing_comma Check if the given token is a trailing comma.
Function _will_be_released_automatically Checks if a call that could be used in a ``with`` statement is used in an alternative construct which would ensure that its __exit__ method is called.
BUILTIN_EXIT_FUNCS = (source)

Undocumented

Value
frozenset(('quit', 'exit'))
CALLS_RETURNING_CONTEXT_MANAGERS = (source)

Undocumented

Value
frozenset(('_io.open',
           'pathlib.Path.open',
           'codecs.open',
           'urllib.request.urlopen',
           'tempfile.NamedTemporaryFile',
           'tempfile.SpooledTemporaryFile',
           'tempfile.TemporaryDirectory',
...
CALLS_THAT_COULD_BE_REPLACED_BY_WITH = (source)

Undocumented

Value
frozenset(('threading.lock.acquire',
           'threading._RLock.acquire',
           'threading.Semaphore.acquire',
           'multiprocessing.managers.BaseManager.start',
           'multiprocessing.managers.SyncManager.start'))
KNOWN_INFINITE_ITERATORS: set[str] = (source)

Undocumented

Value
set(['itertools.count', 'itertools.cycle'])
def _except_statement_is_always_returning(node: nodes.TryExcept, returning_node_class: nodes.NodeNG) -> bool: (source)

Detect if all except statements return.

def _if_statement_is_always_returning(if_node: nodes.If, returning_node_class: nodes.NodeNG) -> bool: (source)

Undocumented

def _is_a_return_statement(node: nodes.Call) -> bool: (source)

Undocumented

def _is_inside_context_manager(node: nodes.Call) -> bool: (source)

Undocumented

def _is_part_of_assignment_target(node: nodes.NodeNG) -> bool: (source)

Check whether use of a variable is happening as part of the left-hand side of an assignment. This requires recursive checking, because destructuring assignment can have arbitrarily nested tuples and lists to unpack.

def _is_part_of_with_items(node: nodes.Call) -> bool: (source)

Checks if one of the node's parents is a ``nodes.With`` node and that the node itself is located somewhere under its ``items``.

def _is_trailing_comma(tokens: list[tokenize.TokenInfo], index: int) -> bool: (source)

Check if the given token is a trailing comma. :param tokens: Sequence of modules tokens :type tokens: list[tokenize.TokenInfo] :param int index: Index of token under check in tokens :returns: True if the token is a comma which trails an expression :rtype: bool

def _will_be_released_automatically(node: nodes.Call) -> bool: (source)

Checks if a call that could be used in a ``with`` statement is used in an alternative construct which would ensure that its __exit__ method is called.