[issue18712] Pure Python operator.index doesn't match the C version.

2021-10-02 Thread Dong-hee Na
Change by Dong-hee Na : -- nosy: +corona10 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue18712] Pure Python operator.index doesn't match the C version.

2021-09-10 Thread Irit Katriel
Irit Katriel added the comment: Reproduced on 3.11. -- nosy: +iritkatriel versions: +Python 3.11 -Python 3.4 ___ Python tracker ___

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-21 Thread Serhiy Storchaka
Changes by Serhiy Storchaka storch...@gmail.com: -- dependencies: +PyNumber_Index() is not int-subclass friendly (or operator.index() docos lie) ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18712

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-19 Thread Zachary Ware
Zachary Ware added the comment: A lot of this discussion has flown a rather unfortunate distance over my head, especially since I've barely had time to follow it. But it looks to me like--given the number of other places that do the same thing as operator.index currently does--there needs to

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-18 Thread Armin Rigo
Armin Rigo added the comment: For completeness, can you post one line saying why the much simpler solution range(a).stop is not accepted? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18712

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Here is a variant with getattr_static(). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18712 ___ ___

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-18 Thread Serhiy Storchaka
Changes by Serhiy Storchaka storch...@gmail.com: Added file: http://bugs.python.org/file31353/operator_index_4.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18712 ___

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: For completeness, can you post one line saying why the much simpler solution range(a).stop is not accepted? Because it is implementation detail. The range() function if it will be implemented in Python needs operator.index(). The main purpose of adding

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-18 Thread Armin Rigo
Armin Rigo added the comment: Ah. If that's the only reason, then that seems a bit like misguided effort... For alternative implementations like PyPy and Jython, the _operator module is definitely one of the simplest ones to reimplement in RPython or Java. Every function is

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-18 Thread Armin Rigo
Armin Rigo added the comment: ...but yes, it's very obvious that exposing _PyType_Lookup() to pure Python is the right thing to do here. This is a central part of the way Python works internally, after all. Moreover, sorry about my previous note: if we started today to write PyPy, then it

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Armin Rigo
Armin Rigo added the comment: Just mentioning it here again, but type(a).__index__(a) is still not perfectly correct. Attached is a case where it differs. I think you get always the correct answer by evaluating range(a).stop. It's admittedly obscure... For example: class A:

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The difference doesn't look significant. In all cases the TypeError is raised. But there was other differences between C and Python versions -- when __index__() returns non-integer. Updated patch fixes this. -- Added file:

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Mark Dickinson
Mark Dickinson added the comment: Just mentioning it here again, but type(a).__index__(a) is still not perfectly correct. Hmm. type(a).__dict__['__index__'](a) ? (With suitable error checks, as in Serhiy's patch.) -- ___ Python tracker

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Armin Rigo
Armin Rigo added the comment: The difference doesn't look significant. In all cases the TypeError is raised. Ok, so here is another case. (I won't go to great lengths trying to convince you that there is a problem, because the discussion already occurred several times; google for example

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Hmm. type(a).__dict__['__index__'](a) ? This variant fails on: class A(int): @staticmethod def __index__(): return 42 -- ___ Python tracker rep...@bugs.python.org

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Mark Dickinson
Mark Dickinson added the comment: Serhiy: Yep, or even on bool. Thanks. Armin: I don't think either of us thinks there isn't a problem here. :-) The Google search you suggested didn't turn up a whole lot of useful information for me. Was there a discussion of this on python-dev at some

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Armin Rigo
Armin Rigo added the comment: This may have been the most recent discussion of this idea (as far as I can tell): http://mail.python.org/pipermail//python-ideas/2012-August/016036.html Basically, it seems to be still unresolved in the trunk Python; sorry, I thought by now it would have been

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Armin Rigo
Armin Rigo added the comment: Sorry, realized that my pure Python algorithm isn't equivalent to _PyType_Lookup() --- it fails the staticmethod example of Serhiy. A closer one would be: for t in type(a).__mro__: if '__index__' in t.__dict__: return

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Here is updated patch which uses Armin's algorithm for lookup special methods and adds special case for int subclasses in index(). I have no idea how the documentation should look. -- Added file:

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-17 Thread Eric Snow
Eric Snow added the comment: Couldn't you make use of inspect.getattr_static()? getattr_static(obj.__class__, '__index__').__get__(obj)() getattr_static() does some extra work to get do the right lookup. I haven't verified that it matches _PyType_Lookup() exactly, but it should be pretty

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Here is a patch. Now the code of operator.index() becomes even more complicated. Perhaps you want suggest other wording for documentation? Some code in stdlib (_pyio.py, bz2.py, connection.py) uses a.__index__() instead of type(a).__index__(a) (with

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-12 Thread Mark Dickinson
New submission from Mark Dickinson: Nitpick: the pure Python version of operator.index (new in Python 3.4, introduced in issue #16694) doesn't match the C version, in that it looks up __index__ on the object rather than the class. iwasawa:cpython mdickinson$ ./python.exe Python 3.4.0a1+

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: We can use type(a).__index__(a). Should we also correct the documentation for operator.index() and operator.length_hint()? -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org

[issue18712] Pure Python operator.index doesn't match the C version.

2013-08-12 Thread Mark Dickinson
Mark Dickinson added the comment: Yes, I think it would make sense to fix the docs as well, at least for Python 3.4. Probably not worth it for the maintenance releases. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18712