[PATCH 4 of 4] ui: avoid mutable default arguments

Matt Mackall mpm at selenic.com
Wed Sep 23 11:16:48 CDT 2015


On Wed, 2015-09-23 at 02:05 -0700, Pierre-Yves David wrote:
> 
> On 09/22/2015 05:15 PM, Siddharth Agarwal wrote:
> > # HG changeset patch
> > # User Siddharth Agarwal <sid0 at fb.com>
> > # Date 1442966194 25200
> > #      Tue Sep 22 16:56:34 2015 -0700
> > # Node ID 75950e78a828c5994bd36974bdfbc5f62a0009a3
> > # Parent  2e9d6b73a2a88c044175a05d32626b18afc0e889
> > ui: avoid mutable default arguments
> 
> eeeeeeeerk, patches 3 and 4 pushed to the clowncopter.

We've got a bunch more {} and [].

$ hg diff
diff -r 60558319ce72 contrib/check-code.py
--- a/contrib/check-code.py	Tue Sep 22 16:56:34 2015 -0700
+++ b/contrib/check-code.py	Wed Sep 23 11:13:25 2015 -0500
@@ -291,6 +291,7 @@
     (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"'),
+    (r'def.*[( ]\w+=\{\}', "don't use mutable default arguments"),
   ],
   # warnings
   [


$ hg check
hgext/histedit.py:645 (pierre-yves at 19021):
 > def findoutgoing(ui, repo, remote=None, force=False, opts={}):
 don't use mutable default arguments
hgext/largefiles/overrides.py:53 (natosha at 16247):
 >     def overridematch(ctx, pats=[], opts={}, globbed=False,
 don't use mutable default arguments
hgext/largefiles/overrides.py:290 (lmoscovicz at 21466):
 >     def overridematchandpats(ctx, pats=[], opts={}, globbed=False,
 don't use mutable default arguments
hgext/largefiles/overrides.py:616 (mpm at 28415):
 >         def overridematch(ctx, pats=[], opts={}, globbed=False,
 don't use mutable default arguments
hgext/largefiles/overrides.py:725 (martinvonz at 27257):
 >         def overridematch(mctx, pats=[], opts={}, globbed=False,
 don't use mutable default arguments
hgext/largefiles/overrides.py:1167 (matt_harbison at 25726):
 > def scmutiladdremove(orig, repo, matcher, prefix, opts={}, dry_run=None,
 don't use mutable default arguments
hgext/mq.py:486 (pmezard at 10184):
 >     def diffopts(self, opts={}, patchfn=None):
 don't use mutable default arguments
hgext/transplant.py:120 (brendan at 3714):
 >     def apply(self, repo, source, revmap, merges, opts={}):
 don't use mutable default arguments
Skipping hgext/zeroconf/Zeroconf.py it has no-check-code
Skipping i18n/polib.py it has no-check-code
mercurial/cmdutil.py:2766 (kbullock at 18688):
 > def commitstatus(repo, node, branch, bheads=None, opts={}):
 don't use mutable default arguments
Skipping mercurial/httpclient/__init__.py it has no-check-code
Skipping mercurial/httpclient/_readers.py it has no-check-code
Skipping mercurial/httpclient/socketutil.py it has no-check-code
mercurial/httpconnection.py:110 (durin42 at 14244):
 >     def request(self, method, uri, body=None, headers={}):
 don't use mutable default arguments
mercurial/localrepo.py:543 (foozy at 21636):
 >     def _tag(self, names, node, message, local, user, date, extra={},
 don't use mutable default arguments
mercurial/scmutil.py:756 (matt_harbison at 29074):
 > def matchandpats(ctx, pats=[], opts={}, globbed=False, default='relpath',
 don't use mutable default arguments
mercurial/scmutil.py:779 (matt_harbison at 29074):
 > def match(ctx, pats=[], opts={}, globbed=False, default='relpath', badfn=None):
 don't use mutable default arguments
mercurial/scmutil.py:791 (matt_harbison at 25726):
 > def addremove(repo, matcher, prefix, opts={}, dry_run=None, similarity=None):
 don't use mutable default arguments
mercurial/templater.py:795 (dirkjan at 8218):
 >     def __init__(self, loader, filters={}, defaults={}):
 don't use mutable default arguments
mercurial/templater.py:832 (brendan at 7396):
 >     def __init__(self, mapfile, filters={}, defaults={}, cache={},
 don't use mutable default arguments



-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list