Changes between Version 1 and Version 2 of Ticket #13394, comment 86


Ignore:
Timestamp:
11/02/13 03:32:00 (8 years ago)
Author:
nbruin
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #13394, comment 86

    v1 v2  
    1313and it's an odd optimization too. The only explanation I can see is that `print` doesn't think `dict` can be subclassed and thus, based on a type test, decides to use `PyDict` routines on it. I'm afraid that our solution won't necessarily work in all places where a `UserDict` would get recognized as a type that needs method resolution.
    1414
    15 '''EDIT:''' I think the problem is that the `dict` type has its `tp_print` field set, so we inherit that routine. Ideally we should override it, but I don't think cython provides support for that. Bug report to cython?
     15'''EDIT:''' I think the problem is that the `dict` type has its `tp_print` field set, so we inherit that routine. Ideally we should override it, but I don't think cython provides support for that. Discussion on [https://groups.google.com/forum/?hl=en#!topic/cython-users/ktsXt_o4M0Q cython-users] has some details. We could hack our way around it by doing
     16{{{
     17cdef extern from "Python.h":
     18    ctypedef struct PyTypeObject:
     19        void * tp_print
     20
     21cdef WeakValueDictionary(dict):
     22    def __init__(self):
     23        ....
     24
     25#clear the tp_print field on the type after PyType_Ready has executed on it.
     26(<PyTypeObject *><void *>WeakValueDictionary).tp_print = NULL
     27}}}
     28It feels like a horrible hack but it does have the desired effect.