Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pyext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions test/test_pyext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys, inspect, types, py.test
import sys, inspect, types, pytest
from pyext import *

def test_overload_argc():
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)