Skip to content

Ruff Cannot Recognise a Variable Usage inside typing.cast #17442

@barmanroys

Description

@barmanroys

Summary

Play ground link.

Context

A test method within a unittest class.

Code
from typing import cast, Tuple
...

def test_run(self):
    """Use the sample initial states and action choices for testing."""
    initial_input: int = 1 # Ruff warns this variable is defined but not used 
    actions: Tuple[int, ...] = (199, 213, 111, 333) # Ruff warns this variable is defined but not used 
    result = cast(
        typ=Tuple[Any],
        val=self.interactor.run(llm_input=initial_input, action_sequence=actions),
    )
    self.assertTupleEqual(tuple1=result, tuple2=(1, 0, True, {}))
    logging.info(msg="Multi-round interactor passed testing.")
Problem

Ruff Cannot recognise the usage of a variable inside typing.cast. Even though it is being used.

System Details
  • ruff 0.11.5
  • uv 0.5.13
  • Operating system: Linux mint 22

Version

0.11.5

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