Lists and Tuples

Just just at xs4all.nl
Wed Dec 10 16:59:16 EST 2003


In article <mailman.204.1070832604.16879.python-list at python.org>,
 "Fredrik Lundh" <fredrik at pythonware.com> wrote:

> Robert Brewer wrote:
> 
> > Now if somebody can just figure out why:
> >
> >     threading.Thread(args=())
> >
> > but:
> >
> >     threading.Timer(args=[])
> >
> > we'll have this topic nailed down pretty well. ;)
> 
> different authors; the threading module itself is really old (1.5?),
> but the Timer class was added in 2.2, and nobody spotted the
> inconsistency at that time.
> 
> not sure if this can/should be fixed; there might be someone out
> there doing:
> 
>     t = threading.Timer(interval, function)
>     t.args.append(value)
>     t.start()

That would be totally broken, mutable default args and all. In the 
Thread class, the mutable kwargs argument isn't so bad, since it's 
assigned to a "private" attribute, but the _Timer class uses a plain 
attr, so is asking for trouble.

Even if I know my code doesn't modify mutable arguments yet need a 
default, I'd still code it like this:

   def foo(kwargs=None):
      if kwargs is None:
         kwargs = {}
      ...

Maybe I'm too strict here, but I think using mutable default arguments 
is at _least_ bad style.

Just




More information about the Python-list mailing list