[PATCH 05 of 21 WIP-PY3K] util: use argcount helper function instead of direct inspection

Matthew Turk matthewturk at gmail.com
Mon Oct 12 16:24:49 CDT 2015


# HG changeset patch
# User Matthew Turk <matthewturk at gmail.com>
# Date 1444683579 18000
#      Mon Oct 12 15:59:39 2015 -0500
# Node ID 915461f26de5f1a1b5b4d4d044c27986c0dad9d4
# Parent  3c52788cd531fe3f134ab09828fe575c4b371d7b
util: use argcount helper function instead of direct inspection

diff -r 3c52788cd531 -r 915461f26de5 mercurial/util.py
--- a/mercurial/util.py	Mon Oct 12 15:59:19 2015 -0500
+++ b/mercurial/util.py	Mon Oct 12 15:59:39 2015 -0500
@@ -35,6 +35,8 @@
 import bz2
 import zlib
 
+from .py3kcompat import argcount
+
 if os.name == 'nt':
     from . import windows as platform
 else:
@@ -412,7 +414,7 @@
 def cachefunc(func):
     '''cache the result of function calls'''
     # XXX doesn't handle keywords args
-    if func.func_code.co_argcount == 0:
+    if argcount(func) == 0:
         cache = []
         def f():
             if len(cache) == 0:
@@ -420,7 +422,7 @@
             return cache[0]
         return f
     cache = {}
-    if func.func_code.co_argcount == 1:
+    if argcount(func) == 1:
         # we gain a small amount of time because
         # we don't need to pack/unpack the list
         def f(arg):
@@ -513,7 +515,7 @@
     '''cache most recent results of function calls'''
     cache = {}
     order = collections.deque()
-    if func.func_code.co_argcount == 1:
+    if argcount(func) == 1:
         def f(arg):
             if arg not in cache:
                 if len(cache) > 20:


More information about the Mercurial-devel mailing list