Patchwork [1,of,7] util: use __code__ (available since py2.6)

login
register
mail settings
Submitter timeless@mozdev.org
Date April 8, 2016, 4:22 p.m.
Message ID <b4f3a8a501aa6134f5ef.1460132565@waste.org>
Download mbox | patch
Permalink /patch/14438/
State Accepted
Headers show

Comments

timeless@mozdev.org - April 8, 2016, 4:22 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1459273403 0
#      Tue Mar 29 17:43:23 2016 +0000
# Node ID b4f3a8a501aa6134f5ef33fd5281cc731e18c0ad
# Parent  c5565fc8848dd084d104ca40c33d1acdfcff8bc6
util: use __code__ (available since py2.6)

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -450,7 +450,7 @@ 
 def cachefunc(func):
     '''cache the result of function calls'''
     # XXX doesn't handle keywords args
-    if func.func_code.co_argcount == 0:
+    if func.__code__.co_argcount == 0:
         cache = []
         def f():
             if len(cache) == 0:
@@ -458,7 +458,7 @@ 
             return cache[0]
         return f
     cache = {}
-    if func.func_code.co_argcount == 1:
+    if func.__code__.co_argcount == 1:
         # we gain a small amount of time because
         # we don't need to pack/unpack the list
         def f(arg):
@@ -700,7 +700,7 @@ 
     '''cache most recent results of function calls'''
     cache = {}
     order = collections.deque()
-    if func.func_code.co_argcount == 1:
+    if func.__code__.co_argcount == 1:
         def f(arg):
             if arg not in cache:
                 if len(cache) > 20: