[Python-3000] default argument surprises

Brett Cannon brett at python.org
Wed Aug 27 20:01:26 CEST 2008


On Wed, Aug 27, 2008 at 9:29 AM, Sam Bishop <samuel.j.bishop at gmail.com> wrote:
> On Tue, Aug 26, 2008 at 8:31 PM, Chris Rebert <cvrebert at gmail.com> wrote:
>> You might then be interested in the following related discussions from
>> last year wherein I proposed something extremely similar:
>>
>> [Python-ideas] proto-PEP: Fixing Non-constant Default Arguments
>> http://mail.python.org/pipermail/python-ideas/2007-January/000121.html
>>
>> [Python-3000] pre-PEP: Default Argument Expressions
>> http://mail.python.org/pipermail/python-3000/2007-February/005712.html
>
> Hmm...  That's too bad.  I like your PEP.  :)
>
> I disagree with Guido's comment about this being related to class
> variables, from a newbie's point of view anyway.  Classes introduce a
> namespace and functions introduce a scope.  What surprises me is that
> functions seem to introduce two scopes: one for variables declared as
> formal parameters and one for variables assigned to within the
> function.
>

But the point is that this is a newbie POV that is based on a
misunderstanding. It's going to be nearly impossible to remove all
possible gotchas from the language based on what a proto-typical
newbie might get tripped up on when it is based on a misunderstanding.
If you don't view everything but function/method bodies as executed
code, then you have a misconception about how Python works.

Perhaps this can be better explained in the tutorial or language
reference. But because something is not being communicated well by the
documentation does not mean it needs to be changed.

-Brett


More information about the Python-3000 mailing list