[C++-sig] method injector and pickling

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Fri Jul 11 00:10:00 CEST 2003


I ran into pickle problems when converting some of the classes in
our application to make use of David's method injector (as explained
in tutorial/doc/quickstart.txt). The problems disappeared when
I added the if statement below to disable injection of
__module__ and __file__. Proactively I added __init__ and
__del__ to the list.

Is this a useful modification? Should we update quickstart.txt
accordingly?

Ralf


from scitbx.array_family import flex

# see boost/libs/python/doc/tutorial/doc/quickstart.txt

boost_python_metaclass = flex.double.__class__

class injector(object):

  class __metaclass__(boost_python_metaclass):

    def __init__(self, name, bases, dict):
      for b in bases:
        if type(b) not in (self, type):
          for k,v in dict.items():
            if (k in ("__init__", "__del__", "__module__", "__file__")):
              continue
            setattr(b,k,v)
      return type.__init__(self, name, bases, dict)


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com




More information about the Cplusplus-sig mailing list