Message349562
| Author | vstinner |
|---|---|
| Recipients | Arfrever, alex, barry, docs@python, eric.snow, ethan.furman, mjacob, ncoghlan, python-dev, rhettinger, serhiy.storchaka, vstinner |
| Date | 2019-08-13.14:26:25 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <1565706385.68.0.496114678154.issue17576@roundup.psfhosted.org> |
| In-reply-to |
| Content | |
|---|---|
It started to write a new issue, but then I found this issue issue (created in 2013!) which is still open. So let me write my comment here instead. The code to convert a number to an integer is quite complex in Python. There are *many* ways to do that and each way has subtle behavior differences (ex: __index__ vs __int__). Python tolerates some behavior which lead to even more confusion. For example, some functions explicitly reject the float type but accept Decimal: * bpo-20861 * bpo-35707 PyLong_Long(obj) calls type(obj).__index__() if it's defined, but it accepts subtypes of int, not only exactly the int type (type(x) == int). This feature is deprecated since Python 3.3 (released in 2012), since this change: commit 31a655411a79b00517cdcd0a2752824d183db792 Author: Serhiy Storchaka <storchaka@gmail.com> Date: Wed Dec 11 21:07:54 2013 +0200 Issue #17576: Deprecation warning emitted now when __int__() or __index__() return not int instance. Introduced _PyLong_FromNbInt() and refactored PyLong_As*() functions. I propose to now fail with an exception if __int__() or __index__() return type is not exactly int. Note: My notes on Python numbers: https://pythondev.readthedocs.io/numbers.html |
|
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2019-08-13 14:26:25 | vstinner | set | recipients: + vstinner, barry, rhettinger, ncoghlan, Arfrever, alex, docs@python, ethan.furman, python-dev, eric.snow, serhiy.storchaka, mjacob |
| 2019-08-13 14:26:25 | vstinner | set | messageid: <1565706385.68.0.496114678154.issue17576@roundup.psfhosted.org> |
| 2019-08-13 14:26:25 | vstinner | link | issue17576 messages |
| 2019-08-13 14:26:25 | vstinner | create | |