Skip to content

Commit

Permalink
Update name and docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Oct 18, 2021
1 parent 0f87c0e commit c45d82e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c45d82e

Please sign in to comment.