This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2016年05月09日 14:02 by serhiy.storchaka, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| int_exact.patch | serhiy.storchaka, 2016年07月01日 12:23 | review | ||
| Messages (7) | |||
|---|---|---|---|
| msg265196 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年05月09日 14:02 | |
The int constructor can return an instance of int subclass. >>> class BadTrunc: ... def __trunc__(self): ... return True ... >>> int(BadTrunc()) True When __int__ returns non-exact int, at least a warning is emitted: >>> class BadInt: ... def __int__(self): ... return True ... >>> int(BadInt()) __main__:1: DeprecationWarning: __int__ returned non-int (type bool). The ability to return an instance of a strict subclass of int is deprecated, and may be removed in a future version of Python. True The constructor of int subclass always return an instance of correct type: >>> class IntSubclass(int): ... pass ... >>> type(IntSubclass(BadTrunc())) <class '__main__.IntSubclass'> >>> type(IntSubclass(BadInt())) __main__:1: DeprecationWarning: __int__ returned non-int (type bool). The ability to return an instance of a strict subclass of int is deprecated, and may be removed in a future version of Python. <class '__main__.IntSubclass'> I don't know if it is worth to deprecate __trunc__ returning non-exact int, since this special method is used in math.trunc(). But I think that the int constructor should convert its result to exact int. If some preparatory period is needed, it can first start to emit FutureWarning. |
|||
| msg265210 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2016年05月09日 16:43 | |
> But I think that the int constructor should convert its result to exact int. Agreed. See also issue 17576 and previous discussions on python-dev (thread started in March, but most of the messages in April): - https://mail.python.org/pipermail/python-dev/2013-March/125022.html - https://mail.python.org/pipermail/python-dev/2013-April/125042.html I don't have strong feelings about `__trunc__` (or `__floor__` and `__ceil__`); it seems fine to me for those to be returning something other than a strict int. |
|||
| msg269663 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年07月01日 12:23 | |
Proposed patch makes int() always returning exact int. |
|||
| msg270626 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年07月17日 10:04 | |
Could you please make a review Mark? |
|||
| msg273057 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2016年08月18日 18:55 | |
> Could you please make a review Mark? Sorry, Serhiy. I missed this. I've got some time off coming up, so I plan to look at this in the next few days. |
|||
| msg273291 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2016年08月21日 10:40 | |
The patch LGTM. I'm still in two minds about whether `__trunc__` should be required to return a strict `int`, but for now it's probably better to go with the status quo. |
|||
| msg273305 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2016年08月21日 17:03 | |
New changeset 81f229262921 by Serhiy Storchaka in branch 'default': Issue #26984: int() now always returns an instance of exact int. https://hg.python.org/cpython/rev/81f229262921 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:30 | admin | set | github: 71171 |
| 2016年08月21日 17:17:05 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: commit review -> resolved |
| 2016年08月21日 17:03:33 | python-dev | set | nosy:
+ python-dev messages: + msg273305 |
| 2016年08月21日 10:41:31 | mark.dickinson | set | assignee: mark.dickinson -> serhiy.storchaka stage: patch review -> commit review |
| 2016年08月21日 10:40:56 | mark.dickinson | set | messages: + msg273291 |
| 2016年08月18日 18:55:03 | mark.dickinson | set | messages: + msg273057 |
| 2016年08月18日 11:52:43 | mark.dickinson | set | assignee: mark.dickinson |
| 2016年07月17日 10:04:38 | serhiy.storchaka | set | messages: + msg270626 |
| 2016年07月01日 12:23:12 | serhiy.storchaka | set | files:
+ int_exact.patch keywords: + patch messages: + msg269663 stage: patch review |
| 2016年05月09日 16:43:36 | mark.dickinson | set | messages: + msg265210 |
| 2016年05月09日 14:02:31 | serhiy.storchaka | create | |