Skip to content

Commit cef60cc

Browse files
Fix false-negative for used-before-assignment with postponed evaluation in function defs (#10482) (#10483)
(cherry picked from commit d363fca) Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
1 parent 5a5a9be commit cef60cc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix false-negative for ``used-before-assignment`` with ``from __future__ import annotations`` in function definitions.
2+
3+
Refs #10482

pylint/checkers/variables.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,17 @@ def _check_consumer(
19491949
# and unevaluated annotations inside a function body
19501950
if not (
19511951
self._postponed_evaluation_enabled
1952-
and isinstance(stmt, (nodes.AnnAssign, nodes.FunctionDef))
1952+
and (
1953+
isinstance(stmt, nodes.AnnAssign)
1954+
or (
1955+
isinstance(stmt, nodes.FunctionDef)
1956+
and node
1957+
not in {
1958+
*(stmt.args.defaults or ()),
1959+
*(stmt.args.kw_defaults or ()),
1960+
}
1961+
)
1962+
)
19531963
) and not (
19541964
isinstance(stmt, nodes.AnnAssign)
19551965
and utils.get_node_first_ancestor_of_type(stmt, nodes.FunctionDef)

0 commit comments

Comments
 (0)