[Python-Dev] Semantics of int(), index() (original) (raw)
Mark Dickinson dickinsm at gmail.com
Tue Apr 2 09🔞29 CEST 2013
- Previous message: [Python-Dev] Semantics of __int__(), __index__()
- Next message: [Python-Dev] Semantics of __int__(), __index__()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Apr 2, 2013 at 8:07 AM, Mark Dickinson <dickinsm at gmail.com> wrote:
On Tue, Apr 2, 2013 at 1:44 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
There's code in the slot wrappers so that if you return a non-int object from either int or index, then the interpreter will complain about it, and if you return a subclass, it will be stripped back to just the base class.
Can you point me to that code? All I could find was PyLongCheck calls (I was looking for PyLongCheckExact).
And indeed:
iwasawa:Objects mdickinson$ /opt/local/bin/python3.3 Python 3.3.0 (default, Sep 29 2012, 08:16:19) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information.
class A: ... def int(self): ... return True ... def index(self): ... return False ... a = A() int(a) True import operator; operator.index(a) False
Which means I have to do int(int(a)) to get the actual integer value. Grr.
Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130402/c2fb85ea/attachment.html>
- Previous message: [Python-Dev] Semantics of __int__(), __index__()
- Next message: [Python-Dev] Semantics of __int__(), __index__()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]