"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pylint/checkers/variables.py" between
pylint-2.14.2.tar.gz and pylint-2.14.3.tar.gz

About: pylint analyzes Python source code looking for bugs and signs of poor quality.

variables.py  (pylint-2.14.2):variables.py  (pylint-2.14.3)
skipping to change at line 1068 skipping to change at line 1068
super().__init__(linter) super().__init__(linter)
self._to_consume: list[NamesConsumer] = [] self._to_consume: list[NamesConsumer] = []
self._checking_mod_attr = None self._checking_mod_attr = None
self._type_annotation_names = [] self._type_annotation_names = []
self._except_handler_names_queue: list[ self._except_handler_names_queue: list[
tuple[nodes.ExceptHandler, nodes.AssignName] tuple[nodes.ExceptHandler, nodes.AssignName]
] = [] ] = []
"""This is a queue, last in first out.""" """This is a queue, last in first out."""
self._postponed_evaluation_enabled = False self._postponed_evaluation_enabled = False
def open(self) -> None:
"""Called when loading the checker."""
self._is_undefined_variable_enabled = self.linter.is_message_enabled(
"undefined-variable"
)
self._is_undefined_loop_variable_enabled = self.linter.is_message_enable
d(
"undefined-loop-variable"
)
def leave_for(self, node: nodes.For) -> None: def leave_for(self, node: nodes.For) -> None:
self._store_type_annotation_names(node) self._store_type_annotation_names(node)
def visit_module(self, node: nodes.Module) -> None: def visit_module(self, node: nodes.Module) -> None:
"""Visit module : update consumption analysis variable """Visit module : update consumption analysis variable
checks globals doesn't overrides builtins. checks globals doesn't overrides builtins.
""" """
self._to_consume = [NamesConsumer(node, "module")] self._to_consume = [NamesConsumer(node, "module")]
self._postponed_evaluation_enabled = is_postponed_evaluation_enabled(nod e) self._postponed_evaluation_enabled = is_postponed_evaluation_enabled(nod e)
skipping to change at line 1340 skipping to change at line 1331
It's important that all 'Name' nodes are visited, otherwise the It's important that all 'Name' nodes are visited, otherwise the
'NamesConsumers' won't be correct. 'NamesConsumers' won't be correct.
""" """
stmt = node.statement(future=True) stmt = node.statement(future=True)
if stmt.fromlineno is None: if stmt.fromlineno is None:
# name node from an astroid built from live code, skip # name node from an astroid built from live code, skip
assert not stmt.root().file.endswith(".py") assert not stmt.root().file.endswith(".py")
return return
self._undefined_and_used_before_checker(node, stmt) self._undefined_and_used_before_checker(node, stmt)
if self._is_undefined_loop_variable_enabled: self._loopvar_name(node)
self._loopvar_name(node)
@utils.only_required_for_messages("redefined-outer-name") @utils.only_required_for_messages("redefined-outer-name")
def visit_excepthandler(self, node: nodes.ExceptHandler) -> None: def visit_excepthandler(self, node: nodes.ExceptHandler) -> None:
if not node.name or not isinstance(node.name, nodes.AssignName): if not node.name or not isinstance(node.name, nodes.AssignName):
return return
for outer_except, outer_except_assign_name in self._except_handler_names _queue: for outer_except, outer_except_assign_name in self._except_handler_names _queue:
if node.name.name == outer_except_assign_name.name: if node.name.name == outer_except_assign_name.name:
self.add_message( self.add_message(
"redefined-outer-name", "redefined-outer-name",
skipping to change at line 1398 skipping to change at line 1388
# We check here instead of before every single return in _check_ consumer() # We check here instead of before every single return in _check_ consumer()
nodes_to_consume += current_consumer.consumed_uncertain[node.nam e] nodes_to_consume += current_consumer.consumed_uncertain[node.nam e]
current_consumer.mark_as_consumed(node.name, nodes_to_consume) current_consumer.mark_as_consumed(node.name, nodes_to_consume)
if action is VariableVisitConsumerAction.CONTINUE: if action is VariableVisitConsumerAction.CONTINUE:
continue continue
if action is VariableVisitConsumerAction.RETURN: if action is VariableVisitConsumerAction.RETURN:
return return
# we have not found the name, if it isn't a builtin, that's an # we have not found the name, if it isn't a builtin, that's an
# undefined name ! # undefined name !
if ( if not (
self._is_undefined_variable_enabled node.name in nodes.Module.scope_attrs
and not ( or utils.is_builtin(node.name)
node.name in nodes.Module.scope_attrs or node.name in self.linter.config.additional_builtins
or utils.is_builtin(node.name) or (
or node.name in self.linter.config.additional_builtins node.name == "__class__"
or ( and any(
node.name == "__class__" i.is_method()
and isinstance(frame, nodes.FunctionDef) for i in node.node_ancestors()
and frame.is_method() if isinstance(i, nodes.FunctionDef)
) )
) )
and not utils.node_ignores_exception(node, NameError) ) and not utils.node_ignores_exception(node, NameError):
):
self.add_message("undefined-variable", args=node.name, node=node) self.add_message("undefined-variable", args=node.name, node=node)
def _should_node_be_skipped( def _should_node_be_skipped(
self, node: nodes.Name, consumer: NamesConsumer, is_start_index: bool self, node: nodes.Name, consumer: NamesConsumer, is_start_index: bool
) -> bool: ) -> bool:
"""Tests a consumer and node for various conditions in which the node sh ouldn't """Tests a consumer and node for various conditions in which the node sh ouldn't
be checked for the undefined-variable and used-before-assignment checks. be checked for the undefined-variable and used-before-assignment checks.
""" """
if consumer.scope_type == "class": if consumer.scope_type == "class":
# The list of base classes in the class definition is not part # The list of base classes in the class definition is not part
 End of changes. 4 change blocks. 
24 lines changed or deleted 12 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)