Mercurial > hg
changeset 26348:b80b2ee71a08
check-code: forbid mutable value for default argument
default value are common to all call. Using mutable value is a classical source
of bug in Python. We forbid it.
The regexp (Courtesy of Matt Mackall) is only catching such value on the first
line of a definition, but that will be good enough for now.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 24 Sep 2015 00:34:15 -0700 |
parents | e9a35411bbbc |
children | 92409f8dff5d |
files | contrib/check-code.py |
diffstat | 1 files changed, 2 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/check-code.py Thu Sep 24 00:54:30 2015 -0700 +++ b/contrib/check-code.py Thu Sep 24 00:34:15 2015 -0700 @@ -291,6 +291,8 @@ (r'os\.path\.join\(.*, *(""|\'\')\)', "use pathutil.normasprefix(path) instead of os.path.join(path, '')"), (r'\s0[0-7]+\b', 'legacy octal syntax; use "0o" prefix instead of "0"'), + # XXX only catch mutable arguments on the first line of the definition + (r'def.*[( ]\w+=\{\}', "don't use mutable default arguments"), ], # warnings [