From 8e98e8b442a29b08dd19aa94fb0789cb712723f1 Mon Sep 17 00:00:00 2001 From: Kazuya O'moto Date: Fri, 24 Feb 2023 22:07:51 +0900 Subject: [PATCH 1/2] Use inspect.signature instead of formatargspec inspect.formatargspec has been deprecated since Python 3.5, and removed in Python 3.11. --- wx/py/introspect.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wx/py/introspect.py b/wx/py/introspect.py index 0bd1a5ca..f21c4a71 100644 --- a/wx/py/introspect.py +++ b/wx/py/introspect.py @@ -175,8 +175,11 @@ def getCallTip(command='', locals=None): pass elif inspect.isfunction(obj): # tip1 is a string like: "getCallTip(command='', locals=None)" - argspec = inspect.getargspec(obj) if not PY3 else inspect.getfullargspec(obj) - argspec = inspect.formatargspec(*argspec) + try: + argspec = str(inspect.signature(obj)) # PY35 or later + except AttributeError: + argspec = inspect.getargspec(obj) if not PY3 else inspect.getfullargspec(obj) + argspec = inspect.formatargspec(*argspec) if dropSelf: # The first parameter to a method is a reference to an # instance, usually coded as "self", and is usually passed From e0a71625e2d5d0f40c740f389dd10128562a07cd Mon Sep 17 00:00:00 2001 From: Kazuya O'moto Date: Fri, 24 Feb 2023 23:11:50 +0900 Subject: [PATCH 2/2] Extract argspec inside paren using re ex. argspec = '(x, /, y, z=3, *args, value: int = 0, **kwargs) -> int' --> 'x, /, y, z=3, *args, value: int = 0, **kwargs' --- wx/py/introspect.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wx/py/introspect.py b/wx/py/introspect.py index f21c4a71..e9c16b7f 100644 --- a/wx/py/introspect.py +++ b/wx/py/introspect.py @@ -3,6 +3,7 @@ things like call tips and command auto completion.""" __author__ = "Patrick K. O'Brien " +import re import sys import inspect import tokenize @@ -214,7 +215,11 @@ def getCallTip(command='', locals=None): tip = '%s%s\n\n%s' % (tip1, tip2, tip3) else: tip = tip1 - calltip = (name, argspec[1:-1], tip.strip()) + # Extract argspec from the signature e.g., (x, /, *, ...) -> int + m = re.search(r'\((.*)\)', argspec) + if m: + argspec = m.group(1) + calltip = (name, argspec, tip.strip()) return calltip def getRoot(command, terminator=None):