compat: make override of createmarkers work on wrapped function
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 19 Mar 2018 15:46:17 -0700
changeset 3575 97530d6e340d
parent 3574 8aba29d8b133
child 3576 89acae8f7e93
compat: make override of createmarkers work on wrapped function If createmarkers() has been wrapped using functools.partial(), the __code__ attribute won't exist. Fix by unwrapping partial functions. I tried to find another attribute to use as proxy for the "__code__.co_argcount < 6", but there were no new functions or similar added in that commit.
hgext3rd/evolve/compat.py
hgext3rd/topic/compat.py
--- a/hgext3rd/evolve/compat.py	Mon Mar 19 11:18:47 2018 -0700
+++ b/hgext3rd/evolve/compat.py	Mon Mar 19 15:46:17 2018 -0700
@@ -8,6 +8,8 @@
 
 import inspect
 
+import functools
+
 from mercurial import (
     copies,
     context,
@@ -54,7 +56,10 @@
 # Wrap obsolete.creatmarkers and make it accept but ignore "operation" argument
 # for hg < 4.3
 createmarkers = obsolete.createmarkers
-if obsolete.createmarkers.__code__.co_argcount < 6:
+originalcreatemarkers = createmarkers
+while isinstance(originalcreatemarkers, functools.partial):
+    originalcreatemarkers = originalcreatemarkers.func
+if originalcreatemarkers.__code__.co_argcount < 6:
     def createmarkers(repo, relations, flag=0, date=None, metadata=None,
                       operation=None):
         return obsolete.createmarkers(repo, relations, flag, date, metadata)
--- a/hgext3rd/topic/compat.py	Mon Mar 19 11:18:47 2018 -0700
+++ b/hgext3rd/topic/compat.py	Mon Mar 19 15:46:17 2018 -0700
@@ -7,6 +7,8 @@
 """
 from __future__ import absolute_import
 
+import functools
+
 from mercurial import (
     obsolete,
     scmutil,
@@ -30,7 +32,10 @@
 # Wrap obsolete.creatmarkers and make it accept but ignore "operation" argument
 # for hg < 4.3
 createmarkers = obsolete.createmarkers
-if obsolete.createmarkers.__code__.co_argcount < 6:
+originalcreatemarkers = createmarkers
+while isinstance(originalcreatemarkers, functools.partial):
+    originalcreatemarkers = originalcreatemarkers.func
+if originalcreatemarkers.__code__.co_argcount < 6:
     def createmarkers(repo, relations, flag=0, date=None, metadata=None,
                       operation=None):
         return obsolete.createmarkers(repo, relations, flag, date, metadata)