On Mon, Aug 26, 2002 at 05:56:52PM -0400, Guido van Rossum wrote: > > It gets harder if you want to remove a method or marker. The problem is > > that there is currently no way to mask inherited attributes. This will > > require either a language extension that will allow you to del them or > > using some other convention for this purpose. > > Can't you use this? > > def B: > def foo(self): pass > > def C: > foo = None # Don't implement foo This comes closer: def raise_attributeerror(self): raise AttributeError RemoveAttribute = property(raise_attributeerror) class A: def f(self): print "method A.f" def g(self): print "method A.g" class B: f = RemoveAttribute a = A() b = B() a.f() a.g() print hasattr(b, "f"), hasattr(B, "f"), hasattr(b, "g"), hasattr(B, "g") try: b.f except AttributeError: print "b.f does not exist (correctly)" else: print "Expected AttributeError not raised" b.g() writing 'b.f' will raise AttributeError, but unfortunately hasattr(B, 'f') will still return True. Jeff
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