Should Python raise a warning for mutable default arguments?
__peter__ at web.de
Fri Aug 22 17:55:13 CEST 2008
bearophileHUGS at lycos.com wrote:
> DrScheme is an implementation of Scheme that is very newbie-friendly.
> It has several limited sub-languages, etc.
> So maybe a command line option can be added to Python3 ( -
> newbie ? :-) ) that just switches on similar warnings, to help newbies
> (in schools, where there's a teacher that encourages to always use
> that command line option) avoid some of the most common traps.
Or maybe bundle pychecker with idle?
$ cat tmp.py
def test(x, a=):
for i in range(5):
$ pychecker tmp.py
[0, 1, 2]
[0, 1, 2, 3]
[0, 1, 2, 3, 4]
tmp.py:2: Modifying parameter (a) with a default value may have unexpected
Though it might be interesting to ask a newbie what he expects when warned
of "unexpected consequences" ;)
More information about the Python-list