Re: [pygccxml-development] Patch to add a little syntactic sugar
Brought to you by:
mbaas,
roman_yakovenko
From: Allen B. <al...@vr...> - 2006-05-17 18:10:53
|
Roman Yakovenko wrote: > On 5/17/06, Allen Bierbaum <al...@vr...> wrote: > >> I have included a patch that I find useful for simplifying decl lookup >> in pyplusplus. >> >> It allows code like the following to be written using the __getitem__ >> interface. >> >> ns = mb.global_ns.namespace( 'my_ns',) >> ns["MyClass"].exclude() >> class_a = ns["ClassA"] >> class_a["doSomething"].include() >> >> It also allows an attribute interface (similar to Pyste). >> >> ns.MyClass.exclude() >> class_a = ns.ClassA >> class_a.doSomething.include() >> >> These both can be used to dramatically reduce the amount of clutter >> (redundant code calls) using in a script to generate bindings. Although >> the second one could be seen as a little dangerous because of potential >> name conflicts, I think the interface of Pyste has proven that people >> like an interface like this because it allows something that feels like >> a very tight domain specific langauge for creating bindings. >> >> I know that neither of these methods is anything more then syntactic >> sugar, but IMHO it is pretty sweet sugar. :) > > > Thanks. I will apply the patch. There is only one question: > Why not to implement the __getattr__ next way: > found_decls = self.decls(name=name, allow_empty=True) > if found_decls: > return found_decls > else: > raise AttributeError > Why do you need treatment for '__' ? I didn't originally have it but without it I was seeing a lot of searches for '__getnewargs__' and '__getstate__'. I don't know why they were happening but I didn't think it was a good idea to spend time searching for decls that we know are not there. It was more of an optimization then anything. -Allen > > >> -Allen > > > Thanks. > > |