This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Mutable default function parameter warning
Type: behavior Stage:
Components: None Versions: Python 2.7, Python 2.6, Python 2.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, surkamp
Priority: normal Keywords:

Created on 2010-08-19 18:42 by surkamp, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg114394 - (view) Author: Sérgio Surkamp (surkamp) Date: 2010-08-19 18:42
The documentation states that the default value of function parameter, if mutable, can change it's default value at runtime due to be evaluated only once on function object creation.

I would like to suggest the inclusion of an default language warning when this kind of construction is used, as it's Python specific behavior and can lead to "strange behavior" or misuse by programmers that are migrating from other languages to Python.

Documentation reference:
http://docs.python.org/reference/compound_stmts.html#function
msg114405 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-08-19 19:06
Please post to python-ideas first.
History
Date User Action Args
2022-04-11 14:57:05adminsetgithub: 53855
2010-08-19 19:06:15benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg114405

resolution: rejected
2010-08-19 18:42:08surkampcreate