Hi Leonardo,
On Sat, Jul 29, 2006 at 09:11:14PM -0400, Leonardo Soto wrote:
> I've recently filled the issue 244 (dict.update() doesn't support
> keywords argument), and tried to solve it in a naive way, just
> modifying the applevel definition to:
>
> def update(d, o, **kwargs):
> (...)
This is a bit messy. It's an app-level definition but it goes through
the interp-level gateway code via the multimethod logic. The first
thing to change is the declared signature of the dict_update
multimethod, also in dicttype.py:
dict_update = SMM('update', 2, defaults=((),), doc="...")
This means "two arguments with a default of () for the second one".
Note that it's where the default comes from, too; not from the
"def update(d, o)" implementation.
Note first a difficulty: if we were implementing this method in pure
Python, we couldn't say 'def update(self, o, **kwargs)' because there is
a name clash between 'o' and the keywords, preventing an explicit 'o'
keyword from being passed. To solve this we would have to declare it
'def update(self, *args, **kwargs)'.
The equivalent solution here is:
dict_update = SMM('update', 1, general__args__=True, doc="...")
^^^^^^^^^^^^^^^^^^^^^^^^
def update(d, *args, **kwargs):
if len(args) > 1:
raise TypeError("update takes at most 1 (non-keyword) argument")
...
dict_update__ANY = app.interphook("update")
^^^^
But it doesn't work yet, because I'm just discovering that we have no
support for *args/**kwargs in app.interphook()!
Trying to fix this now...
Armin
_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev