-
-
Notifications
You must be signed in to change notification settings - Fork 459
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
Fix type of min_value and max_value on DecimalField #951
Fix type of min_value and max_value on DecimalField #951
Conversation
These should at the very least allow Decimals. Technically you can send in anything that's comparable to a Decimal, but I'm not sure if it makes sense to allow floats. Could allow both ints and Decimals I guess?
django-stubs/forms/fields.pyi
Outdated
@@ -125,8 +125,8 @@ class DecimalField(IntegerField): | |||
def __init__( | |||
self, | |||
*, | |||
max_value: Optional[int] = ..., | |||
min_value: Optional[int] = ..., | |||
max_value: Optional[Decimal] = ..., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> from decimal import Decimal
>>> Decimal(1.5) > 1.2
True
>>> Decimal(1.5) > 1
True
Let's include int
and float
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I've included them now. Kinda disagree about floats though, because the imprecise nature of floats. If you've decided to use a decimal field I assume you want accuracy, even though a float technically works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
These should at the very least allow Decimals. Technically you can send in anything that's comparable to a Decimal, but I'm not sure if it makes sense to allow floats. Could allow both ints and Decimals I guess?
In the Django codebase these arguments are sent to
MinValueValidator
andMaxValueValidator
which just doesa < b
/a > b
.