Skip to content

Constrained TypeVars with Any default #20184

@srittau

Description

@srittau

Bug Report

In python/typeshed#13683 I'm trying to change a type var to the following:

_I = TypeVar("_I", int, bytes, float, bool, default=Any)  # possibly memoryview types

Unfortunately, mypy complains: error: TypeVar default must be one of the constraint types [misc]. While this is of course generally sound advice, a default of Any should always be permissible, as this allows memoryview to stand for any possible memoryview type. Without it, users are forced to write memoryview[Any] in every instance, which is unreasonable.

Your Environment

  • Mypy version used: 1.18.2

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions