Mercurial > public > mercurial-scm > hg-stable
comparison contrib/check-code.py @ 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 | 20de1ace07a9 |
children | b3f7516fa50e |
comparison
equal
deleted
inserted
replaced
26347:e9a35411bbbc | 26348:b80b2ee71a08 |
---|---|
289 (r'release\(.*wlock, .*lock\)', "wrong lock release order"), | 289 (r'release\(.*wlock, .*lock\)', "wrong lock release order"), |
290 (r'\b__bool__\b', "__bool__ should be __nonzero__ in Python 2"), | 290 (r'\b__bool__\b', "__bool__ should be __nonzero__ in Python 2"), |
291 (r'os\.path\.join\(.*, *(""|\'\')\)', | 291 (r'os\.path\.join\(.*, *(""|\'\')\)', |
292 "use pathutil.normasprefix(path) instead of os.path.join(path, '')"), | 292 "use pathutil.normasprefix(path) instead of os.path.join(path, '')"), |
293 (r'\s0[0-7]+\b', 'legacy octal syntax; use "0o" prefix instead of "0"'), | 293 (r'\s0[0-7]+\b', 'legacy octal syntax; use "0o" prefix instead of "0"'), |
294 # XXX only catch mutable arguments on the first line of the definition | |
295 (r'def.*[( ]\w+=\{\}', "don't use mutable default arguments"), | |
294 ], | 296 ], |
295 # warnings | 297 # warnings |
296 [ | 298 [ |
297 (r'(^| )pp +xxxxqq[ \n][^\n]', "add two newlines after '.. note::'"), | 299 (r'(^| )pp +xxxxqq[ \n][^\n]', "add two newlines after '.. note::'"), |
298 ] | 300 ] |