quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@pobox.com
Subject Re: Patch to allow kwargs in publisher.py
Date Thu, 03 Oct 2002 21:33:31 GMT
On Thu, Oct 03, 2002 at 04:56:19PM -0400, Gregory (Grisha) Trubetskoy wrote:
> 
> Thanks for the patch. I'm not sure I like the "pass", why not simply do
> this:
> 
>       if not (fc.co_flags & 0x08):
>           for name in args.keys():
>               if name not in expected:
>                   del args[name]

A matter of coding style, I guess; I've always preferred to write "if
(condition): pass else: (do something)" than "if not (condition): (do
something)" when the condition is complicated enough -- and, in fact,
that's become my default way of doing negative-condition ifs even when
(as in this case) the condition isn't too complicated. What you suggest
should work fine.

Note that once you apply this patch, you'll run into the util.py bug
that I just submitted another patch for. That patch was invisible until
now because None was, of course, not in expected and so args[None] would
be removed.

> 
> 
> On Wed, 2 Oct 2002 rmunn@pobox.com wrote:
> 
> > @@ -180,10 +180,17 @@ fc = object.im_func.func_code expected =
> > fc.co_varnames[1:fc.co_argcount]
> >
> > -        # remove unexpected args -        for name in args.keys():
> > -            if name not in expected: -                del
> > args[name] +        # does it want keyword args?  +        #
> > co_flags & 0x04 is set if a function wants *args syntax +        #
> > co_flags & 0x08 is set if a function wants **kwargs syntax +
> > if fc.co_flags & 0x08: +            # don't strip unexpected args if
> > function wants **kwargs +            pass +        else: +
> > # remove unexpected args +            for name in args.keys(): +
> > if name not in expected: +                    del args[name]
> >
> >          result = apply(object, (), args)
> >
> 
> 

-- 
Robin Munn
rmunn@pobox.com

Mime
View raw message