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:40:04
|
Roman Yakovenko wrote: > On 5/17/06, Allen Bierbaum <al...@vr...> wrote: > >> Roman Yakovenko wrote: >> >> > 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. > > > I don't have a problem with exceptions you raise. I have a problem > when exception > is not raised. User wrote MyClass.named, when he meant MyClass.name and > MyClass has named variable. > > Almost same example, different view: > class X{ > string name; > }; > > User can not use X.name syntax, because name is the property of every > declaration. > > So he is forced to switch to alternative syntax: X["name"]. > > I don't like this. Yes, I don't see anyway around this. That is why this syntax is a little dangerous. It is nice when it works but there are certain reserved words that it is not going to work with. Personally I don't think this is enough reason to not use the API, but it does mean that users need to be careful when they do (or atleast they need to be warned about the potential problems in the documentation). It would have to be considered an advanced feature unless someone can think of a way around this problem. -Allen |