From c45d82ef4c0b29128c1969e4ddf5e8d5adf8b251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Mon, 18 Oct 2021 20:32:06 +0200 Subject: [PATCH] Update name and docstring --- pylint/checkers/variables.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 8ab167485d..30f87d632b 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -1195,7 +1195,7 @@ def visit_name(self, node: nodes.Name) -> None: ) elif self._is_only_type_assignment(node, defstmt): self.add_message("undefined-variable", node=node, args=node.name) - elif self._is_first_level_self_referring_annotation(node, defstmt): + elif self._is_first_level_self_reference(node, defstmt): self.add_message( "used-before-assignment", node=node, args=node.name ) @@ -1575,18 +1575,12 @@ def _is_only_type_assignment(node: nodes.Name, defstmt: nodes.Statement) -> bool return True @staticmethod - def _is_first_level_self_referring_annotation( + def _is_first_level_self_reference( node: nodes.Name, defstmt: nodes.Statement ) -> bool: - """Check if a method annotation refers to its own class on the first level. - This schould be done with quotes: - def MyClass(): - def method(parameter: "MyClass"): - pass - def other_method(self) -> bool: - def inner_method(self, other: MyClass) -> bool: - pass - pass + """Check if a first level method's annotation or default values + refers to its own class. See tests/functional/u/use/used_before_assignement.py + for additional examples. """ if isinstance(defstmt, nodes.ClassDef) and node.frame().parent == defstmt: # Check if used as type annotation