[Python-Dev] type categories
Mon, 26 Aug 2002 20:39:44 -0500
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:
RemoveAttribute = property(raise_attributeerror)
def f(self): print "method A.f"
def g(self): print "method A.g"
f = RemoveAttribute
a = A()
b = B()
print hasattr(b, "f"), hasattr(B, "f"), hasattr(b, "g"), hasattr(B, "g")
except AttributeError: print "b.f does not exist (correctly)"
else: print "Expected AttributeError not raised"
writing 'b.f' will raise AttributeError, but unfortunately hasattr(B, 'f')
will still return True.