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:18:20
|
Roman Yakovenko wrote: > On 5/17/06, Roman Yakovenko <rom...@gm...> 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() > > > I like this part of the patch > >> > It also allows an attribute interface (similar to Pyste). >> > >> > ns.MyClass.exclude() >> > class_a = ns.ClassA >> > class_a.doSomething.include() > > > This one I like less. If user made some mistake and spelled wrong > property name > of the class_t or namespace_t and there is a declaration with that name, > then .... I prefer to apply the patch without __getattr__ part. > > Thoughts? I assume you mean something like: MyClass.someMethod.call_policies = .... so what if they spell it 'call_pooicies', it that case it will raise the exception that python would normal raise and just throw and AttributeError. In the case of trying to look up a decl and spelling that decl wrong, for example: MyClass.someMethod_bad it still throws an AttributeError because that is the standard way to deal with a python attribute lookup problem. It would be nice if the exception included the name that failed, but I don't see a way to do this. I thought about just allowing a failed find to throw the pyplusplus RuntimeError exception for a failed lookup, but this would make all the decl classes behave dramatically different then they way python would expect them to work normally. For example in a previous e-mail I talk about how there are some failed attemtps to look up '__newstate__'. The code that is failing with this lookups is able to work correctly (I would guess) because it catches the AttributeError exception to detect that the lookup failed. If we changed it so the classes didn't throw this exception anymore, this code would fail because it would not be expecting a RuntimeError. So, it is not a perfect solution, but it seems like a reasonable one since it makes the attribute lookup keep behaving as standard python lookups would. -Allen |