Skip to content

runtime-cast-value (TC006) shouldn't apply to stubs #15176

@Avasam

Description

@Avasam

Found this whilst applying various Ruff groups on typeshed.

According to the updated typing spec for typing enums (see Mypy: Change to Enum Membership Semantics and https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members, this is the recommended way to type an enum in stubs where the type is known but the value isn't:

class Key(enum.Enum):
    alt = cast(KeyCode, ...)
    alt_l = cast(KeyCode, ...)
    alt_r = cast(KeyCode, ...)
    alt_gr = cast(KeyCode, ...)
    # ...

This will trigger runtime-cast-value (TC006)

Related: #15132

Ruff: 0.8.4
Command: ruff check --preview --select=TC006 --isolated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions