[Python-Dev] More C API abstraction for user defined types (original) (raw)
Petre Galan Petre.Galan at gmail.com
Sun Jul 18 07:12:41 CEST 2010
- Previous message: [Python-Dev] More C API abstraction for user defined types
- Next message: [Python-Dev] More C API abstraction for user defined types
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Nick Coghlan <ncoghlan gmail.com> writes:
On Wed, Jul 14, 2010 at 11:50 PM, Petre Galan <Petre.Galan gmail.com wrote: No. The right interface is PyNumberLong. The purpose of the PyNumberIndex (and nbindex slot) is as index in slicing. Allowing other objects to say "I'm a real integer, treat me as one" is exactly what the nbindex slot is for (see PEP 357). The use as an index in slicing was just the primary initial use case and the one that was chosen as the name for the new slot because nbint was already taken for the lossy transformation. Indexing is not (and never has been) intended to be the only use case.
PyNumber_Long is the right interface as it's the right way to do it. PyNumber_Index allows me to compute a value as index in slicing, value that may be different that the integer behaviour of object. PyNumber_Index is serving it's purpose as index in slicing, beyond that it's getting abused. As for related discussions, float should not implement nb_int slot but be resolved in int's constructor.
Petre
- Previous message: [Python-Dev] More C API abstraction for user defined types
- Next message: [Python-Dev] More C API abstraction for user defined types
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]