LSP and constructors with first-class classes

John J. Lee jjl at pobox.com
Fri Aug 31 16:13:41 EDT 2001


On Sun, 26 Aug 2001, John J. Lee wrote:
> would be satisfied.  In Python, however, someone (the future me, for
> example) might reasonably expect this to work:
>
> class TheirFitUser(Fit):
>     def foo(self, fit_class):
>         fit = fit_class(data)
>         [...]
>
> This will break on MyFit, of course.
>
> So, is this unavoidable, or have I arguably made a mistake in subclassing
> from Fit in this case?  In which case, how should I have organised
> things...?
[...]

Well, I guess it is pretty obvious, re-reading this.  __init__ shouldn't
(in fact, wasn't in the first place, really) be part of the interface to
the base class.  I guess I had some kind of blind spot for the particular
case of __init__, for some reason.

My ability to be stupid like this with my own design / code is a good
argument for PEP 245, I think...


John




More information about the Python-list mailing list