[New-bugs-announce] [issue4619] Invalid Behaviour When a Default Argument is a Mutable Object

Robert Hunger report at bugs.python.org
Wed Dec 10 14:55:37 CET 2008

New submission from Robert Hunger <rhunger at gmx.ch>:

Reopening of issue 4181.

Evaluating default parameter values when the function definition is
executed is a design bug.

Even the documentation of this behaviour (see
http://docs.python.org/reference/compound_stmts.html#index-754) makes
this clear by stating: "This is generally not what was intended." It
then makes a suggestion for a workaround ("A way around this ..."). Only
bugs need workarounds.

An interface or behaviour should fulfil a users expectation for the
"normal" case, not for some "special" case. For a default parameter
value a user expects that whenever this function gets called a new
instance of a mutable object is created. This is much closer to the
current behaviour for non-mutable objects.

Usage cases for the current default behaviour are less common.

components: Interpreter Core
messages: 77541
nosy: Pasha2009, christian.heimes, rhr
severity: normal
status: open
title: Invalid Behaviour When a Default Argument is a Mutable Object
type: behavior
versions: Python 2.4, Python 2.5, Python 3.0

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list