Commit c1e41ac8 authored by Kirill Smelkov's avatar Kirill Smelkov

golang: tests: Fix fmtargspec on py3.11

Starting from python3.11 inspect.formatargspec was removed:

    f = <function test_func.<locals>.zzz at 0x7fb6d265fec0>

        def fmtargspec(f): # -> str
            with warnings.catch_warnings():
                warnings.simplefilter('ignore', DeprecationWarning)
    >           return inspect.formatargspec(*inspect.getargspec(f))
    E           AttributeError: module 'inspect' has no attribute 'formatargspec'

    golang/golang_test.py:1823: AttributeError

We were already handling formatargspec deprecation in 45f4df9e (golang:
tests: Silence inspect deprecation warning), but now is the time to
actually replace its usage.

-> Fix it by using `str(inspect.signature(f))` instead of
   `inspect.formatargspec(*inspect.getargspec(f))`.
parent 304464e0
......@@ -30,7 +30,7 @@ import os, sys, inspect, importlib, traceback, doctest
from subprocess import Popen, PIPE
import six
from six.moves import range as xrange
import gc, weakref, warnings
import gc, weakref
import re
from golang import _golang_test
......@@ -1818,8 +1818,11 @@ def assertDoc(want, got):
# ...
# fmtargspec(f) -> '(x, y=3)'
def fmtargspec(f): # -> str
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
# inspect.formatargspec is deprecated since py3.5 and was removed in py3.11
# -> use inspect.signature instead.
if six.PY3:
return str(inspect.signature(f))
else:
return inspect.formatargspec(*inspect.getargspec(f))
def test_fmtargspec():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment