From: Jihoon Kim Date: Fri, 21 Apr 2023 05:16:54 +0000 (+0900) Subject: DeprecationWarning: `formatargspec` is deprecated since Python 3.5. X-Git-Tag: accepted/tizen/unified/20230423.230419~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a3e7dc08e62017b48b6d79ed1b6e1edd32454997;p=platform%2Fcore%2Fuifw%2Fnlp.git DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Change-Id: I904273414d7090872a0d1e64c78a5fe378324820 Signed-off-by: Jihoon Kim --- diff --git a/nlp_resource_data/nltk/decorators.py b/nlp_resource_data/nltk/decorators.py index b61db66..0e33984 100644 --- a/nlp_resource_data/nltk/decorators.py +++ b/nlp_resource_data/nltk/decorators.py @@ -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"] + """ 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__,