changeset 6538:d20e5eaba766

compat: make inspect.getargspec() work with functools.partial on Python 2 This is required now because we wrap precheck() in core to check topic namespaces before any history rewrites.
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 10 Jul 2023 16:13:45 -0300
parents 80d5d4e587f7
children 45689da4ed41
files hgext3rd/evolve/rewriteutil.py
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/rewriteutil.py	Thu Jun 22 21:51:37 2023 -0300
+++ b/hgext3rd/evolve/rewriteutil.py	Mon Jul 10 16:13:45 2023 -0300
@@ -11,6 +11,8 @@
 #   happy one piece of it (and hopefully, able to reuse it in other core
 #   commands).
 
+import functools
+
 from mercurial import (
     cmdutil,
     commands,
@@ -60,8 +62,13 @@
 
     <action> can be used to control the commit message.
     """
+    if not pycompat.ispy3 and isinstance(corerewriteutil.precheck, functools.partial):
+        # inspect.getargspec() on py2 cannot inspect functools.partial objects
+        # directly, so we need to provide it with the underlying function
+        args = pycompat.getargspec(corerewriteutil.precheck.func).args
+    else:
+        args = pycompat.getargspec(corerewriteutil.precheck).args
     # hg <= 6.1 (d4752aeb20f1)
-    args = pycompat.getargspec(corerewriteutil.precheck).args
     if r'check_divergence' in args:
         return corerewriteutil.precheck(repo, revs, action,
                                         check_divergence=check_divergence)