New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

Currently PyNumber_Index() can return something that's an instance of a strict 
subclass of int. For example PyNumber_Index(Py_True) returns Py_True. The same 
for operator.index():

>>> import operator
>>> operator.index(True)
True

The proposed PR makes it always return an int.

To avoid possible overhead for creating temporary integer object, added private 
function _PyNumber_Index() with the past behavior. It can be used for 
short-living integer objects which for which only its value will be used, but 
not its methods. For example in the implementation of PyLong_AsLong() and 
similar functions.

See also issue17576.

----------
components: Interpreter Core
messages: 370054
nosy: barry, mark.dickinson, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Make PyNumber_Index() always returning an exact int instance
type: enhancement
versions: Python 3.10

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40792>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to