Skip to content

new rule - invalid cast #3725

Description

@DetachHead

basedpyright's reportInvalidCast rule detects casts that are likely a mistake by validating that the types overlap:

from typing import cast


cast(str, 1)
Conversion of type `Literal[1]` to type `str` may be a mistake because neither type sufficiently overlaps with the other.  If this was intentional, convert the expression to `object` first.

(typescript also does the same thing)

it would be nice if pyrefly had a rule for this as well

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions