[Python-ideas] fixing mutable default argument values (original) (raw)

Joel Bender jjb5 at cornell.edu
Wed Jan 17 15:19:19 CET 2007


Where the <>s indicate these special semantics.

The syntax bothers me, but launched an idea: How about separating parameter default value issues from instance specific definition time objects?

 def foo(a, b=4, c=None):
     local d = Bar([2,3,4])
     ...

The function code can decide if it wants to use c, provided by the caller, or d when no value for c is given. The developer may decide that None is not a good value for 'no value for c', but that's a design decision.

You can do this now with:

 def foo(a, b=4, c=None):
     ...

 foo.func_dict['d'] = Bar([2,3,4])

But I would rather see this inside foo(), jamming variables into the func_dict bothers me too :-).

The new keyword would work for classes, but be a functional noop:

 class Snorf:
     local eggs = 3
     spam = 4

Joel



More information about the Python-ideas mailing list