Skip to content

Fix false-negative for used-before-assignment with postponed evaluation in function defs #10482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10482.false_negative
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix false-negative for ``used-before-assignment`` with ``from __future__ import annotations`` in function definitions.

Refs #10482
12 changes: 11 additions & 1 deletion pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,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)
Expand Down
Loading