[Python-Dev] Symmetry arguments for API expansion (original) (raw)
Nathaniel Smith njs at pobox.com
Wed Mar 21 12:46:06 EDT 2018
- Previous message (by thread): [Python-Dev] Symmetry arguments for API expansion
- Next message (by thread): [Python-Dev] Symmetry arguments for API expansion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mar 21, 2018 05:40, "Steven D'Aprano" <steve at pearwood.info> wrote:
I don't want to change the behaviour of pow(), but we shouldn't dismiss the possibility of some other numeric function wanting to treat values N.0 and N the same. Let's say, an is_prime(x) function that supports floats as well as ints:
is_prime(3.0) # True
is_prime(3.00001) # False
For me this is an argument against is_integer() rather than for it :-). is_prime(float) should obviously[1] be a TypeError. Primality is only meaningfully defined over the domain of integers, and this is a case where operator.index is exactly what you want.
Of course it's just an example, and perhaps there are other, better examples. But it makes me nervous that this is the best example you could quickly come up with.
-n
[1] Warning: I am not Dutch. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180321/147215d8/attachment.html>
- Previous message (by thread): [Python-Dev] Symmetry arguments for API expansion
- Next message (by thread): [Python-Dev] Symmetry arguments for API expansion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]