Tim Hicks writes:
 > I think I've found a bug in ExternalMethod, but I don't know if it's
 > already been fixed or not.
 > Basically, the call signature of ExternalMethods seems to get mixed up
 > sometimes.  I'm running Zope 2.5.1 on Linux.
 > Here's a small demonstration of the bug:
 > --test.py--
 > def test(self, a_string, an_int, a_named_arg=1):
 >     """bug provoking?"""
 >     template =  """a_string = %s; type(a_string) -> %s\n
 > an_int = %s; type(an_int) -> %s\n
 > a_named_arg = %s; type(a_named_arg) -> %s"""
 >     return template % (a_string, type(a_string), an_int, type(an_int),
 > a_named_arg, type(a_named_arg))
 > ----
 > --Script (Python)--
 > return container.test('tim', 10, a_named_arg=(1,1))
 > return container.test('tim', 10, (1,1))
 > ----
 > You can see the dodgy behaviour by switching between the two test() calls
 > in the Script (Python).
This is not a bug but a documented "feature".

  The automatic "self" passing magic only happens when you
  call the method with one positional argument less than required.
  (This does not apply to ZPublisher which uses a different way.)
  Your External Method has 3 required and one optional argument.

  In your first case, you pass 2 required positional arguments
  and give the optional a different value. As one required positional
  argument is missing, "self" is passed in automatically.

  In your second case, you pass 3 required positional arguments.
  "self" is not passed in automatically passed in automatically.

Some say magic is bad ....
Pass your self explicitly!


Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to