i can't get too in depth with your code here, but since a few of your
other posts have similar issue i thought i would try and alleviate
some of your pain.
first off, avoid unnecessary logic during class creation. try using
setattr() after the fact, or using the 3-arg type() class constructor.
this is a scoping problem/bug in pyjs ... do the logic outside class
creation.
tbh, i'm not sure the status of globals() and locals() off-hand, but
neither are required for dynamic creation of object members ... ever.
using them for such makes the code less understandable, and may rely
on implementation details, eg. for locals():
Note The contents of this dictionary should not be modified; changes
may not affect the values of local and free variables used by the
interpreter.
... straight from python 2.7 docs. globals is simply the __dict__ of
a module, so:
import moduleX
setattr(moduleX, some_identifier_that_is_dynamic, func)
... is exactly the same as performing:
globals()[some_identifier_that_is_dynamic] = func
... from within `moduleX`. while i'm not sure off-hand pyjs will
tolerate it, i have in the past imported the current module, and
setattr() on itself ... you simply can't use symbols that have not
been created yet. for example, to maintain backward compatibility, i
did this in pyjd/__init__.py:
#TODO: very ugly to self-import and setattr(self) ... remove ASAP!
import pyjd
[...]
for key, value in _manager._conf.iteritems():
setattr(pyjd, key, value)
... in short, there is nothing here that setattr()/getattr() cannot
handle; i think if you reorganize a bit, and shoot for less exotic
patterns, you will have no trouble squeezing all the dynamism you can
handle from pyjs ;-)
--
C Anthony