Define a Python class which can optionally use __slots__ according to a runtime variable -
a python module use has updated , classes use __slots__
, break functionality i've relied upon. there few solutions this:
- copy code own repo
__slots__
hacked out. easiest, i'd prefer not to. - remove
__slots__
monkey patching. wrote gloriously hacky function searches classes in module, ,__slots__
replaced cloned class__dict__
added , member descriptors , slots removed.
solution 2 works, feels hack. i'd prefer build way allows module optionally turn use of __slots__
on or off, , issue pull request author. turns out pretty tricky.
my first attempt:
module.py:
use_slots = true class someclass(object): if use_slots: __slots__ = ()
if can ensure use_slots
set false before module.py
imported anywhere (and therefore elaborated) works, delicate , breaks unexpectedly.
a factory class ideal, return different classes based on use_slots
library peppered if obj.__class__ == someclass
rather isinstance(obj, someclass)
won't work.
i've spent far long on now, have idea how this?
Comments
Post a Comment