[New-bugs-announce] [issue3403] Unexpected default arguments behaviour

SukkoPera report at bugs.python.org
Fri Jul 18 10:41:36 CEST 2008


New submission from SukkoPera <sr at sukkology.net>:

I have just encountered a Python behaviour I wouldn't expect. Take
the following code:

------------------------------------------------------------------------
class Parent:
        a = 1

        def m (self, param = a):
                print "param = %d" % param

class Child (Parent):
        a = 2

p = Parent ()
p.m ()

c = Child ()
c.m ()
------------------------------------------------------------------------

I would expect to receive the following output:
param = 1
param = 2

But actually I get:
param = 1
param = 1

Is this the correct behaviour, and then why, or is it a bug? For
reference, I am using Python 2.5.1 on GNU/Linux.

There has been a short discussion about this at
http://groups.google.it/group/comp.lang.python/browse_thread/thread/9f740eea131e7ef2/56fd4e120a069a1d#56fd4e120a069a1d.

----------
components: None
messages: 69943
nosy: SukkoPera
severity: normal
status: open
title: Unexpected default arguments behaviour
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3403>
_______________________________________


More information about the New-bugs-announce mailing list