diff --git a/doc/whatsnew/fragments/10482.false_negative b/doc/whatsnew/fragments/10482.false_negative new file mode 100644 index 0000000000..f689436b8b --- /dev/null +++ b/doc/whatsnew/fragments/10482.false_negative @@ -0,0 +1,3 @@ +Fix false-negative for ``used-before-assignment`` with ``from __future__ import annotations`` in function definitions. + +Refs #10482 diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 5f5259e79a..f54153341c 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -1949,7 +1949,17 @@ def _check_consumer( # and unevaluated annotations inside a function body if not ( self._postponed_evaluation_enabled - and isinstance(stmt, (nodes.AnnAssign, nodes.FunctionDef)) + and ( + isinstance(stmt, nodes.AnnAssign) + or ( + isinstance(stmt, nodes.FunctionDef) + and node + not in { + *(stmt.args.defaults or ()), + *(stmt.args.kw_defaults or ()), + } + ) + ) ) and not ( isinstance(stmt, nodes.AnnAssign) and utils.get_node_first_ancestor_of_type(stmt, nodes.FunctionDef)