Skip to content

Commit ea5d18f

Browse files
Add comments
1 parent 8562cea commit ea5d18f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pylint/checkers/variables.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -2289,26 +2289,26 @@ def _is_variable_violation(
22892289
annotation_return = True
22902290
if frame.returns.name in defframe.locals:
22912291
definition = defframe.locals[node.name][0]
2292-
if (
2293-
definition.lineno is None
2294-
or definition.lineno < frame.lineno
2295-
):
2296-
# Detect class assignments with a name defined earlier in the
2297-
# class. In this case, no warning should be raised.
2298-
maybe_before_assign = False
2299-
else:
2300-
maybe_before_assign = True
2292+
# no warning raised if a name was defined earlier in the class
2293+
maybe_before_assign = (
2294+
definition.lineno is not None and definition.lineno >= frame.lineno
2295+
)
23012296
else:
23022297
maybe_before_assign = True
23032298
# Using a name defined in the module if this is a nested function.
23042299
elif (
2300+
# defframe is the class containing the function.
2301+
# It shouldn't be nested: expect its parent to be a module.
23052302
(defframe_parent := next(defframe.node_ancestors()))
23062303
and isinstance(defframe_parent, nodes.Module)
2304+
# frame is the function inside the class.
23072305
and (frame_ancestors := tuple(frame.node_ancestors()))
2306+
# Does that function have any functions as ancestors?
23082307
and any(
23092308
isinstance(ancestor, nodes.FunctionDef)
23102309
for ancestor in frame_ancestors
23112310
)
2311+
# And is its last ancestor the same module as the class's?
23122312
and frame_ancestors[-1] is defframe_parent
23132313
):
23142314
annotation_return = True

0 commit comments

Comments
 (0)