DeprecationWarning: `formatargspec` is deprecated since Python 3.5. 79/291779/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Fri, 21 Apr 2023 05:16:54 +0000 (14:16 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Fri, 21 Apr 2023 05:17:09 +0000 (14:17 +0900)
Change-Id: I904273414d7090872a0d1e64c78a5fe378324820
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
nlp_resource_data/nltk/decorators.py

index b61db66..0e33984 100644 (file)
@@ -26,6 +26,18 @@ import inspect
 
 sys.path = old_sys_path
 
+def __cleansignatureparam(signature):
+    """
+    Removes the default definition in a Signature parameter
+    passed as string.
+    """
+    listsignature = str(signature)[1:-1].split(",")
+    for counter, param in enumerate(listsignature):
+        if param.count("=") > 0:
+            listsignature[counter] = param[0:param.index("=")].strip()
+        else:
+            listsignature[counter] = param.strip()
+    return ", ".join(listsignature)
 
 def getinfo(func):
     """
@@ -34,6 +46,7 @@ def getinfo(func):
     - argnames (the names of the arguments : list)
     - defaults (the values of the default arguments : tuple)
     - signature (the signature : str)
+    - fullsignature (the full signature : Signature)
     - doc (the docstring : str)
     - module (the module name : str)
     - dict (the function __dict__ : str)
@@ -52,21 +65,24 @@ def getinfo(func):
 
     >>> info["signature"]
     'self, x, y, *args, **kw'
+
+    >>> info["fullsignature"]
+    <Signature (self, x=1, y=2, *args, **kw)>
     """
     assert inspect.ismethod(func) or inspect.isfunction(func)
     if sys.version_info[0] >= 3:
         argspec = inspect.getfullargspec(func)
     else:
         argspec = inspect.getargspec(func)
-    regargs, varargs, varkwargs, defaults = argspec[:4]
+    regargs, varargs, varkwargs = argspec[:3]
     argnames = list(regargs)
     if varargs:
         argnames.append(varargs)
     if varkwargs:
         argnames.append(varkwargs)
-    signature = inspect.formatargspec(
-        regargs, varargs, varkwargs, defaults, formatvalue=lambda value: ""
-    )[1:-1]
+    fullsignature = inspect.signature(func)
+    # Convert Signature to str
+    signature = __cleansignatureparam(fullsignature)
 
     # pypy compatibility
     if hasattr(func, '__closure__'):
@@ -80,6 +96,7 @@ def getinfo(func):
         name=func.__name__,
         argnames=argnames,
         signature=signature,
+        fullsignature=fullsignature,
         defaults=func.__defaults__,
         doc=func.__doc__,
         module=func.__module__,