overriding methods - two questions

Paul McGuire ptmcg at austin.rr.com
Fri Nov 16 12:10:31 EST 2007


On Nov 16, 11:03 am, Donn Ingle <donn.in... at gmail.com> wrote:
> Hi,
> Here's a framework for the questions:
>
> --- In a module, part of an API ---
> class Basis ( object ):
>  def foo ( self, arg ):
>   pass
>
> --- In user's own code ---
> class Child ( Basis ):
>  def foo ( self, not, sure ):
>   ...
>
> Question 1:
>
> Given that the user of the API can choose to override foo() or not, how can
> I control the signature that they use? In the example the user has chosen
> bad arguments and Python will complain, but it's describing the sig of the
> *overridden* method and not the one in the parent class.

Actually, Python is complaining about your user's poor choice of
argument names. 'not' is a reserved keyword.  Change it to 'naught' or
'knot' or 'not_' and Python will accept this just fine.

Whether this is a good idea or not is a separate question.  But given
Python's philosophy of "you are the human, so you must know what you
are doing" (which is both an assumption and a directive), I don't
think you will find much language machinery to prevent it.

-- Paul


-- Paul



More information about the Python-list mailing list