Paul Prescod wrote: > Gordon McMillan wrote: > > This proposal changes those semantics. Hooking an attribute > > masks anything in a base class with that name. That's probably > > a good thing, but it should be made explicit since that's not > > the way __getattr__ behaves. > > I don't see the difference. > > def __attr_XXX__( self, op, va ): > Parent.__attr_XXX__( self, op, val ) > > You can still chain if you want. You can? Your proposal only specified that when the class object is being created, method names of the form __attr_XXX__ would cause stuff to happen in the way the class is built. You never said that accesses to things named __YYY_XXX__ on another object would also get transformed into something else. Also, what if the base class just has "attr" - not a hook at all? It will be masked by the hook (which is the difference in behavior I was pointing out). > > Similarly, there's a difference from __setattr__. If you assign > > to the instance.__dict__, the hook will no longer apply for > > that instance / attribute. > > That's true. > > > Also note that while this is *safer* than __xxxattr__, it's > > still not *safe*. Infinite recursion is less likely, but still > > easily achieved. > > The ability to recurse infinitely is a property of methods in > general, not this method in particular. Okay, it is a little more > likely because of a logic flaw but I don't see that as being > unsafe. And earlier I said: > > Overriding a method with > > multiple base class implementations of that method with the > > desire to chain to one or more of the base class > > implementations of that method is a mess. It's not more of a > > mess because the method is named __getattr__. ... So I guess we're even, since we've used the same argument both ways. > I see the current __getattr__ hacks as being unsafe because in a > deep inheritance hierarchy a seemingly insignicant addition in > one place will break code somewhere else. Deep inheritance hierarchies are unpythonic <0.001 wink>. - Gordon
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4