-
Notifications
You must be signed in to change notification settings - Fork 258
Support for Range Types? #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Interesting. I feel like a range type is a bit too specific. What it's essentially doing here is to make sure that in: from typing import RangeType, Tuple
ZipCode = RangeType(low=501, high=99950):
def get_gps_coordinate(code: ZipCode) -> Tuple[float, float]:
pass
|
IIRC Pascal had range types ( There are lots of edge cases though, since the common arithmetic operations aren't closed on range types. In the PEP 484 world your best alternative is |
I propose to close this issue. |
OK, for short ranges people can use unions of literal types -- |
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:
Another language that has range types is Ada, which lets you define range types like so:
The text was updated successfully, but these errors were encountered: