One Worry for 2.2
Mitch Chapman
chapman at bioreason.com
Wed Jul 18 14:05:49 EDT 2001
Pete Shinners wrote:
>
> i'm excited for the new features coming in 2.2. reading some
> release notes, i found a new difference that bothers me.
>
> """
> There's one very specific (and fortunately uncommon) bug that
> used to go undetected, but which is now reported as an error:
> class A:
> def foo(self): pass
>
> class B(A): pass
>
> class C(A):
> def foo(self):
> B.foo(self)
>
> Here, C.foo wants to call A.foo, but by mistake calls B.foo.
> In the old system, because B doesn't define foo, B.foo is
> identical to A.foo, so the call would succeed. In the new
> system, B.foo is marked as a method requiring a B instance,
> and a C is not a B, so the call fails.
> """
>
> now in my mind's understanding of OO, if class B inherits
> from class A, then class B has a foo() function. what this
> is implying is that only _instances_ of class B have a foo()
> function.
B does have a foo method. The problem is that C is derived
from A, not from B. So an instance of C shouldn't be
allowed to pass itself to B.foo.
--
Mitch
Who is sometimes able to pass himself off as a programmer,
even though he isn't descended from one.
More information about the Python-list
mailing list