Skip to content

Support for Range Types? #554

Closed
Closed
@chang

Description

@chang

Is it possible to define a range of integers as a type? Sometimes we might want to constrain an input to a certain range of values.

For example, a US ZIP code must be a 5 digit value. I didn't know this before to opening the issue, but apparently the lowest ZIP code is in Holtsville, New York (00501) and the highest ZIP code is in Ketchikan, Alaska (99950). It would be great if we could define a type like this:

from typing import RangeType, Tuple

ZipCode = RangeType(low=501, high=99950):

def get_gps_coordinate(code: ZipCode) -> Tuple[float, float]:
    ...

Another language that has range types is Ada, which lets you define range types like so:

type ZipCode is range 00501 .. 99950;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions