[pypy-dev] Objects and types in the stdobjspace
holger krekel
hpk at trillke.net
Tue Jun 10 15:26:36 CEST 2003
[Armin Rigo Tue, Jun 10, 2003 at 02:13:23PM +0200]
thanks for your answers. reducing the mail to one point ...
> > > def any_list_extend(space, w_list, w_otherlist):
> > > return space.inplace_add(w_list, w_otherlist)
> > >
> > > W_ListType.list_extend.register(any_list_extend, W_ANY, W_ANY)
>
> Not sure how to reduce this, however. I am not too fond of name-based magic.
> Function attributes would be handy but there is no nice way to define them
> before the body of the function. Docstring-based hacks are bad bad bad. And
> the following has already been (justifiably) rejected as not good-looking and
> requiring quite some metaclass hacks:
>
> class __magic__(W_ANY, W_ANY):
> def list_extend(space, w_list, w_otherlist):
> return space.inplace_add(w_list, w_otherlist)
Evil.
> One more (really magic too) alternative I could think of is
>
> def any_list_extend(space, w_list, w_otherlist, __impl__=(W_ANY, W_ANY)):
> return space.inplace_add(w_list, w_otherlist)
I was thinking more along these lines ...
def list_extend__any_any(space, w_list, w_otherlist):
return space.inplace_add(w_list, w_otherlist)
which is bulk-registered at the end of the file like this:
for name, obj in vars().items():
if hasattr(obj, 'func_code'): # or some other selector
funcname, sig = name.split('__')
getattr(space, funcname).register(obj, ssig=sig.split('_'))
cheers,
holger
More information about the Pypy-dev
mailing list