class NamesConsumer: (source)
A simple class to handle consumed, to consume and scope type info of node locals.
Method | __init__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | get |
Return a list of the nodes that define `node` from this scope. |
Method | mark |
Mark the given nodes as consumed for the name. |
Instance Variable | node |
Undocumented |
Property | consumed |
Undocumented |
Property | consumed |
Retrieves nodes filtered out by get_next_to_consume() that may not have executed. |
Property | scope |
Undocumented |
Property | to |
Undocumented |
Static Method | _branch |
Undocumented |
Static Method | _check |
Check for a case described in https://github.com/PyCQA/pylint/issues/5683. |
Static Method | _defines |
Undocumented |
Static Method | _defines |
Return True if some child of `node` defines the name `name`, raises, or returns. |
Static Method | _exhaustively |
Return True if there is a collectively exhaustive set of paths under this `if_node` that define `name`, raise, or return. |
Static Method | _recursive |
Return True if any Continue node can be found in descendants of `stmt` before encountering `break_stmt`, ignoring any nested loops. |
Static Method | _uncertain |
Return any nodes in ``found_nodes`` that should be treated as uncertain because they are in an except block. |
Static Method | _uncertain |
Return any nodes in ``found_nodes`` that should be treated as uncertain. |
Static Method | _uncertain |
Undocumented |
Method | _uncertain |
Identify nodes of uncertain execution because they are defined under tests that evaluate false. |
Instance Variable | _atomic |
Undocumented |
Instance Variable | _if |
Undocumented |
Return a list of the nodes that define `node` from this scope. If it is uncertain whether a node will be consumed, such as for statements in except blocks, add it to self.consumed_uncertain instead of returning it. Return None to indicate a special case that needs to be handled by the caller.
Mark the given nodes as consumed for the name. If all of the nodes for the name were consumed, delete the name from the to_consume dictionary
Retrieves nodes filtered out by get_next_to_consume() that may not have executed. These include nodes such as statements in except blocks, or statements in try blocks (when evaluating their corresponding except and finally blocks). Checkers that want to treat the statements as executed (e.g. for unused-variable) may need to add them back.
def _check_loop_finishes_via_except(node:
nodes.NodeNG
, other_node_try_except: nodes.TryExcept
) -> bool
:
(source)
¶
Check for a case described in https://github.com/PyCQA/pylint/issues/5683. It consists of a specific control flow scenario where the only non-break exit from a loop consists of the very except handler we are examining, such that code in the `else` branch of the loop can depend on it being assigned. Example: for _ in range(3): try: do_something() except: name = 1 <-- only non-break exit from loop else: break else: print(name)
def _defines_name_raises_or_returns(name:
str
, node: nodes.NodeNG
) -> bool
:
(source)
¶
Undocumented
def _defines_name_raises_or_returns_recursive(name:
str
, node: nodes.NodeNG
) -> bool
:
(source)
¶
Return True if some child of `node` defines the name `name`, raises, or returns.
def _exhaustively_define_name_raise_or_return(name:
str
, node: nodes.NodeNG
) -> bool
:
(source)
¶
Return True if there is a collectively exhaustive set of paths under this `if_node` that define `name`, raise, or return.
def _recursive_search_for_continue_before_break(stmt:
nodes.Statement
, break_stmt: nodes.Break
) -> bool
:
(source)
¶
Return True if any Continue node can be found in descendants of `stmt` before encountering `break_stmt`, ignoring any nested loops.
def _uncertain_nodes_in_except_blocks(found_nodes:
list[ nodes.NodeNG]
, node: nodes.NodeNG
, node_statement: nodes.Statement
) -> list[ nodes.NodeNG]
:
(source)
¶
Return any nodes in ``found_nodes`` that should be treated as uncertain because they are in an except block.
def _uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(found_nodes:
list[ nodes.NodeNG]
, node_statement: nodes.Statement
) -> list[ nodes.NodeNG]
:
(source)
¶
Return any nodes in ``found_nodes`` that should be treated as uncertain. Nodes are uncertain when they are in a try block and the ``node_statement`` being evaluated is in one of its except handlers.
def _uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(found_nodes:
list[ nodes.NodeNG]
, node_statement: nodes.Statement
) -> list[ nodes.NodeNG]
:
(source)
¶
Undocumented
list[ nodes.NodeNG]
, node: nodes.NodeNG
) -> list[ nodes.NodeNG]
:
(source)
¶
Identify nodes of uncertain execution because they are defined under tests that evaluate false. Don't identify a node if there is a collectively exhaustive set of paths that define the name, raise, or return (e.g. every if/else branch).