Skip to content
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/10019.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Exclude ``__all__`` and ``__future__.annotations`` from ``unused-variable``.

Closes #10019
8 changes: 8 additions & 0 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3285,6 +3285,14 @@ def _check_globals(self, not_consumed: Consumption) -> None:
continue
if self._is_exception_binding_used_in_handler(node, name):
continue
if isinstance(node, nodes.AssignName) and node.name == "__all__":
continue
if (
isinstance(node, nodes.ImportFrom)
and name == "annotations"
and node.modname == "__future__"
):
continue
self.add_message("unused-variable", args=(name,), node=node)

# pylint: disable = too-many-branches
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Test `unused-variable` is not emitted for either case of `__future__.annotations` or `__all__`"""


from __future__ import annotations


__all__ = [ "apple" ]


def apple():
"""A public function"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[variables]
allow-global-unused-variables=no
Loading