[Zope] External method default arg weirdness

Dieter Maurer dieter@handshake.de
Wed, 9 May 2001 22:02:19 +0200 (CEST)


Paul Winkler writes:
 > Uhhh... duh, you're right. The methods I was actually using have
 > "self" as first parameter.
 > 
 > But I don't understand why that affects the rest of the
 > parameters??? Very un-pythonic.
I agree. The more modern Python scripts solve the same problem
much better.

The motivation for this "feature":

  Often External Methods should behave like methods.
  Sometimes, they should not.

  The implementers used the following heuristics to distinguish
  between these two cases:

    First, it is tried to call the method with the parameters
    provided. If this raises a "TypeError" and the
    first parameter is called "self", then the
    call is retried, this time with "aq_parent" as first
    parameter.

  This magic works only, if the method is called with
  precisely one parameter less then the required
  arguments. It breaks very likely, when there are
  default parameters. In this case, you need to pass
  the "self" parameter explicitly and can not count on
  the magic.


Dieter