Skip to content

Commit d363fca

Browse files
authored
Fix false-negative for used-before-assignment with postponed evaluation in function defs (#10482)
1 parent 9e72867 commit d363fca

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
@@ -1929,7 +1929,17 @@ def _check_consumer(
19291929
# and unevaluated annotations inside a function body
19301930
if not (
19311931
self._postponed_evaluation_enabled
1932-
and isinstance(stmt, (nodes.AnnAssign, nodes.FunctionDef))
1932+
and (
1933+
isinstance(stmt, nodes.AnnAssign)
1934+
or (
1935+
isinstance(stmt, nodes.FunctionDef)
1936+
and node
1937+
not in {
1938+
*(stmt.args.defaults or ()),
1939+
*(stmt.args.kw_defaults or ()),
1940+
}
1941+
)
1942+
)
19331943
) and not (
19341944
isinstance(stmt, nodes.AnnAssign)
19351945
and utils.get_node_first_ancestor_of_type(stmt, nodes.FunctionDef)

0 commit comments

Comments
 (0)