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:

  1. copy code own repo __slots__ hacked out. easiest, i'd prefer not to.
  2. 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

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -