Skip to content

Referencing an otherwise unused variable in an argument to Annotated falsely triggers F841 #17196

@bkis

Description

@bkis

Summary

The following code shows how ruff check --isolated (0.8.2 through 0.11.3) falsely interprets variables used in arguments to Annotated as "unused" (exact same code in the playground):

from typing import Annotated, Literal


def type_annotations_from_tuple():
    annos = (str, "foo", "bar")  # unused? really?
    return Annotated[annos]


def type_annotations_from_filtered_tuple():
    annos = (str, None, "foo", None, "bar")  # still unused?
    return Annotated[tuple([a for a in annos if a is not None])]


def literals_from_tuple():
    string_literals = ("foo", "bar")
    return Literal[string_literals]  # but this counts as "used"?

Version

at least >=0.8.2, <=0.11.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions