Skip to content
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

Number type hint #2

Closed
Polandia94 opened this issue Feb 7, 2025 · 1 comment
Closed

Number type hint #2

Polandia94 opened this issue Feb 7, 2025 · 1 comment

Comments

@Polandia94
Copy link
Contributor

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.

Related Issues & References
python/mypy#3186
https://peps.python.org/pep-0484/#the-numeric-tower

@Brixt18
Copy link
Owner

Brixt18 commented Feb 10, 2025

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.

@Brixt18 Brixt18 closed this as completed Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants