[Bf-committers] PyRNA type definition changes (postpone beta until end of week)
ideasman42 at gmail.com
Thu Sep 9 02:49:58 CEST 2010
On Thu, Sep 9, 2010 at 12:18 AM, Alex Fraser <alex at phatcore.com> wrote:
> Hi Campbell,
> On Thu, Sep 9, 2010 at 9:18 AM, Campbell Barton <ideasman42 at gmail.com> wrote:
>> --- Proposed solution
>> Follow the way operators work, treat properties as class attributes so...
>> ...is replaced by
>> bpy.types.Scene.myprop = bpy.props.BoolProperty()
>> del bpy.types.Scene.myprop
> It is certainly less verbose, but didn't we recently move away from
> treating properties as attributes in the BGE? For consistency, maybe
> it should be:
> bpy.types.Scene["myprop"] = bpy.props.BoolProperty()
> del bpy.types.Scene["myprop"]
> On the other hand, using attributes might be better if properties are
> more formally defined than in the BGE.
in fact the BGE and 2.5 rna api are the same in this way.
Both allow defining user properties via dictionary like syntax, this
bypasses the rna api.
obj["someprop"] = "Value"
But the BGE doesnt have a way to extend the the internal types (beyond
typical python subclassing) as we do with RNA so I dont think theres a
assigning attributes to a class works in pure python too, eg.
>>> class Foo:
>>> Foo.MyProp = property(lambda self: "Hello World")
>>> inst = Foo()
So you can see that assigning properties this way is in keeping with
the rest of python.
The main problem is that we now need to override the
setattr/getattr/delattr using a metaclass and make a special exception
when a blender property is assigned, looking into this now.
More information about the Bf-committers