[Python-Dev] type categories
jepler@unpythonic.net
jepler@unpythonic.net
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:
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