From b7d66649fcbc47f4c01e7789f9a559760b1cbcea Mon Sep 17 00:00:00 2001 From: John Doe Date: Thu, 27 Mar 2025 17:01:39 +0300 Subject: [PATCH 1/2] add support for pyhthon 3.11+ --- pyext.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyext.py b/pyext.py index 2f4645a..2ebe8ff 100644 --- a/pyext.py +++ b/pyext.py @@ -115,12 +115,13 @@ def modify_function(f, globals={}, name=None, code=None, defaults=None, def _gettypes(args): return tuple(map(type, args)) -oargspec = inspect.getargspec +if hasattr(inspect, 'getargspec'): + oargspec = inspect.getargspec -def _argspec(func): - return _targspec(func, oargspec) + def _argspec(func): + return _targspec(func, oargspec) -inspect.getargspec = _argspec + inspect.getargspec = _argspec try: import IPython From d948f43954745a823a5a868c8282fb3c8ece6069 Mon Sep 17 00:00:00 2001 From: John Doe Date: Thu, 27 Mar 2025 17:15:22 +0300 Subject: [PATCH 2/2] update py.test to pytest and add support for python 3.11+ --- test/test_pyext.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/test_pyext.py b/test/test_pyext.py index 1ed72d9..ce3a5d9 100644 --- a/test/test_pyext.py +++ b/test/test_pyext.py @@ -1,4 +1,4 @@ -import sys, inspect, types, py.test +import sys, inspect, types, pytest from pyext import * def test_overload_argc(): @@ -11,8 +11,9 @@ def f(): return 0 assert f() == 0 assert f(1) == 1 assert f(1, 2) == 2 - with py.test.raises(TypeError): f(1, 2, 3) - assert len(inspect.getargspec(f).args) == 0 + with pytest.raises(TypeError): f(1, 2, 3) + argspec_func = getattr(inspect, 'getargspec', inspect.getfullargspec) + assert len(argspec_func(f).args) == 0 def test_overload_args(): @overload.args(str, int) @@ -27,8 +28,9 @@ def f(): return assert f(0) == int assert f('s') == str assert f('s', 0) == (str, int) - with py.test.raises(TypeError): f(0, 's') - assert len(inspect.getargspec(f).args) == 0 + with pytest.raises(TypeError): f(0, 's') + argspec_func = getattr(inspect, 'getargspec', inspect.getfullargspec) + assert len(argspec_func(f).args) == 0 class x(object): @overload.args(str, is_cls=True) def f(self, s): return 1 @@ -99,4 +101,4 @@ def x(a, b): return 0 x.__annotations__ = {'a': int, 'b': str} x = overload.args(None)(x) assert x(1, 's') == 0 - with py.test.raises(TypeError): x(1, 2) + with pytest.raises(TypeError): x(1, 2)