You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue: quantity is defined as Number, but all type checkers consider that int is not a subtype of Number.
Details:
In all tests and examples, quantity is an int, but it could also be a float or a Decimal (even though Decimal is not part of Number). Despite this, all three types would work fine.
Possible Solutions
We should decide on the expected behavior:
Restrict quantity to int (probably the most common use case).
Allow int and float.
Allow int, float, and Decimal, with a specific error when an operation involves both Decimal and float.
Whichever option we choose, we should update the documentation to clarify what type quantity is expected to be.
I haven't really thought about the parameter to be a specific type of number (int, float, Decimal or other) but it should be, as it says, a number.
So, I would not restrict the type hint to int, so as the dev could use any kind of number they're working with, but I do think the 3rd approach you propose is the one we could take.
About the docs, the update will change the respective doc-string. And the readme (and other docs outside the code itself) will be updated soon as long I can work on it.
Issue:
quantity
is defined asNumber
, but all type checkers consider that int is not a subtype ofNumber
.Details:
In all tests and examples,
quantity
is anint
, but it could also be afloat
or aDecimal
(even thoughDecimal
is not part ofNumber
). Despite this, all three types would work fine.Possible Solutions
We should decide on the expected behavior:
quantity
toint
(probably the most common use case).int
andfloat
.int
,float
, andDecimal
, with a specific error when an operation involves bothDecimal
andfloat
.Whichever option we choose, we should update the documentation to clarify what type quantity is expected to be.
Related Issues & References
python/mypy#3186
https://peps.python.org/pep-0484/#the-numeric-tower
The text was updated successfully, but these errors were encountered: