[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-06 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: should is a wonderful word when it comes to external APIs. We currently have a couple of problems: 1. The concrete APIs will fail noisily if given an instance of something that isn't a list, but may fail *silently* if given a subclass that

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-06 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org added the comment: 2011/4/6 Nick Coghlan rep...@bugs.python.org: Nick Coghlan ncogh...@gmail.com added the comment: should is a wonderful word when it comes to external APIs. We currently have a couple of problems: 1. The concrete APIs will fail

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-06 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Why not add fast paths to the generic functions if that's what you're concerned about? It's unexpected for the user of the functions and breaks years of tradition. What if someone calls PyList_Append on a custom type that doesn't do as they

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-06 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: 1. It's an external API. We *don't control* most of the potentially broken code, so saying just fix the call sites effectively solves nothing and leaves classes like OrderedDict at risk of subtle silent corruption whenever they are passed to

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-06 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: Having convinced myself that Raymond's original suggestion can't be implemented safely, I have an alternative (arguably even more radical) proposal: Deprecate the public concrete API functions that modify object state. Put an underscore in

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-06 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: 1. It's an external API. We *don't control* most of the potentially broken code, so saying just fix the call sites effectively solves nothing and leaves classes like OrderedDict at risk of subtle silent corruption whenever they are passed to a

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-06 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: Changing the affected components. Antoine and Benjamin are right, this needs to be handled as a documentation and education problem. Raymond's suggestion can too easily trigger infinite recursion and mine would block legitimate use cases in

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-06 Thread Raymond Hettinger
Raymond Hettinger raymond.hettin...@gmail.com added the comment: One thing that could be done is to have an optional warning in the mutating concrete C API functions that gets triggered whenever the input doesn't have an exact type match. That will let people discover incorrect uses. We

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-06 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: I thought about a warning, but the problem is that a subclass using the concrete API as part of its *implementation* of the associated slot or method is actually perfectly correct usage. I'm not sure this is enough to give up on the idea of

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-05 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: I may have found another use case for this functionality. Currently, the Python code in heapq.py accepts arbitrary sequences (that are sufficiently compatible with the Sequence ABC), but the C code in _heapq only permits use of a concrete

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-05 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: I added a few commments on Daniel's draft patch. However, I'm getting nervous about the performance impact of all these extra pointer comparisons. We should probably hold off on this until more of the macro benchmark suite runs on Py3k so we

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-04-05 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org added the comment: I find this extremely ugly. The correct way to handle this is to use the generic methods themselves. Really, the type-specific names should only be used when you have just created the type or done PyXXX_CheckExact() yourself on it.

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-03-20 Thread Daniel Urban
Daniel Urban urban.dani...@gmail.com added the comment: Here is a patch for list. It modifies the following C API functions: PyList_SetItem PyList_Insert PyList_Append PyList_SetSlice PyList_Sort PyList_Reverse _PyList_Extend It also includes tests (with ctypes). I plan to do next the same

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-03-20 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Hmm, making PyList_* an abstract API doesn't make sense to me. These functions do exactly what they say: they operate on concrete instances of list (they are documented as part of the concrete API). With that reasoning, we should have fallback

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-03-20 Thread Andreas Stührk
Changes by Andreas Stührk andy-pyt...@hammerhartes.de: -- nosy: +Trundle ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10977 ___ ___

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-03-20 Thread Raymond Hettinger
Raymond Hettinger raymond.hettin...@gmail.com added the comment: By the way, PyList_SetItem() already has an abstract counterpart called PyObject_SetItem(), so changing this one seems useless. The problem isn't a lack of available abstract functions. If some code uses PyObject_SetItem(),

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-03-20 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: The problem isn't a lack of available abstract functions. Then what is it exactly? You are arguing for PyList_SetItem() to have the same semantics as PyObject_SetItem(), but what's the point of having two functions which do exactly the same

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-03-20 Thread Nick Coghlan
Nick Coghlan ncogh...@gmail.com added the comment: It's largely a backwards compatibility hack, but the concrete methods also have an optimised fast path that the generic methods lack. So (for example), PyList_SetItem would now mean this is *probably* a list, so check for that and use the

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-03-20 Thread Raymond Hettinger
Raymond Hettinger raymond.hettin...@gmail.com added the comment: I'm just pointing out a problem. Lots of existing code uses the concrete API and that code can break subclasses of builtin types (possibly resulting in segfaults). I don't really care what is done about it. I'm just observing

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-01-28 Thread Daniel Urban
Changes by Daniel Urban urban.dani...@gmail.com: -- nosy: +durban ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10977 ___ ___ Python-bugs-list

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-01-22 Thread Éric Araujo
Changes by Éric Araujo mer...@netwok.org: -- nosy: +eric.araujo title: Concrete object C API needs abstract path for subclasses of builtin types - Concrete object C API needs abstract path for subclasses of builtin types ___ Python tracker

[issue10977] Concrete object C API needs abstract path for subclasses of builtin types

2011-01-21 Thread Raymond Hettinger
New submission from Raymond Hettinger rhettin...@users.sourceforge.net: Currently, the concrete object C API bypasses any methods defined on subclasses of builtin types. It has long been accepted that subclasses of builtin types need to override many methods rather than just a few because