Skip to content

Feature request: option that completely disallows typing.cast #17077

Open
@wyattscarpenter

Description

@wyattscarpenter

Feature

An option that disallows use of typing.cast, eg --disallow-casts

Pitch

cast() gets around static type safety without ensuring dynamic type correctness. Sometimes you have to use it—you know how it is—but it's not ideal. (For instance, mypy documentation seems to imply the main use of cast is when the typechecker or type annotations aren't quite good enough.) That means, in my opinion, cast is a great candidate to have a option disallowing its use, to ensure code quality in codebases where it is not needed.

I also think this option should be enabled in strict mode, but I suspect other people might disagree.

This proposal is distinct from the --warn-redundant-casts option that already exists, but is somewhat similar.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions