[Zope-Perl] Python void context

Chris McDonough chrism@digicool.com
Fri, 26 May 2000 12:54:02 -0400


> Currently I just ignore keyword arguments so this is doable.  It might
> be in conflict with other mappings of keyword arguments that we want
> to do insted, but reserving some namesspace like __*, i.e. use
> __context="list" etc. should be ok.

reserving a namespace using an __ prefix might be a bad choice as Python
mangles variables in function bodies that start with __ ala:

>>> class c:
...   def f(self, v):
...      self.__a = 1
...
>>> i.f(1)
>>> dir(i)
['_c__a']

Here's how it might break:

>>> class c:
...   def f(self, __v):
...      print __v
...
>>> i = c()
>>> i.f(1)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in f
NameError: _c__v


> We might pass keyword arguments directly to perl as either a hash
> reference or simply as key value pairs after the other arguments.
> That means a function declared as:
> 
>    sub foo {
>        my($a, $b, %args) = @_;
>        ...
>    }
> 
> could be called from python as
> 
>    foo(1, 2, foo=3, bar=4)
> 
> In this case the '=' will basically be treated like ",", but is kind
> of ok since that is just what perl's '=>' actually is.  The bad thing
> about this is that python programmers might expect
> 
>    foo(b = 3, foo = 3, a = 1, bar=4)
> 
> to actually work (pass the same arguments as above).
> 
> --Gisle


Geez, I forget all the rules for calling Perl subroutines with
mixed-primitive and pseudo-keyword arguments.  Looks like I'll have to
dig out my Perl Cookbook.  :-) 

But I'm wondering if you wouldn't be better off implementing a proxy
object that pulls apart the passed-in arguments and packages them up in
some sane way to hand off to the Perl subroutine in order to make the
latter method do the right thing.  Note that this is just idle
speculation.