Issue 3403: Unexpected default arguments behaviour (original) (raw)
Issue3403
Created on 2008-07-18 08:41 by SukkoPera, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (2) | ||
---|---|---|
msg69943 - (view) | Author: (SukkoPera) | Date: 2008-07-18 08:41 |
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. | ||
msg69944 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
Date: 2008-07-18 09:01 |
This is another "problem" due to the fact that parameter defaults are evaluated once during function definition, not every time the function is called. This is expected and will not change. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:36 | admin | set | github: 47653 |
2008-07-18 09:01:09 | georg.brandl | set | status: open -> closedresolution: not a bugmessages: + nosy: + georg.brandl |
2008-07-18 08:41:35 | SukkoPera | create |