Skip to content

Commit 4fe1c4b

Browse files
authored
gh-103553: Improve test_inspect: add more assertions, remove unused (#103554)
1 parent 0097c36 commit 4fe1c4b

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Lib/test/test_inspect.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -1820,8 +1820,7 @@ def test_errors(self):
18201820
self.assertEqualException(f, '2, 3, 4')
18211821
self.assertEqualException(f, '1, 2, 3, a=1')
18221822
self.assertEqualException(f, '2, 3, 4, c=5')
1823-
# XXX: success of this one depends on dict order
1824-
## self.assertEqualException(f, '2, 3, 4, a=1, c=5')
1823+
self.assertEqualException(f, '2, 3, 4, a=1, c=5')
18251824
# f got an unexpected keyword argument
18261825
self.assertEqualException(f, 'c=2')
18271826
self.assertEqualException(f, '2, c=3')
@@ -1832,17 +1831,19 @@ def test_errors(self):
18321831
self.assertEqualException(f, '1, a=2')
18331832
self.assertEqualException(f, '1, **{"a":2}')
18341833
self.assertEqualException(f, '1, 2, b=3')
1835-
# XXX: Python inconsistency
1836-
# - for functions and bound methods: unexpected keyword 'c'
1837-
# - for unbound methods: multiple values for keyword 'a'
1838-
#self.assertEqualException(f, '1, c=3, a=2')
1834+
self.assertEqualException(f, '1, c=3, a=2')
18391835
# issue11256:
18401836
f3 = self.makeCallable('**c')
18411837
self.assertEqualException(f3, '1, 2')
18421838
self.assertEqualException(f3, '1, 2, a=1, b=2')
18431839
f4 = self.makeCallable('*, a, b=0')
1844-
self.assertEqualException(f3, '1, 2')
1845-
self.assertEqualException(f3, '1, 2, a=1, b=2')
1840+
self.assertEqualException(f4, '1, 2')
1841+
self.assertEqualException(f4, '1, 2, a=1, b=2')
1842+
self.assertEqualException(f4, 'a=1, a=3')
1843+
self.assertEqualException(f4, 'a=1, c=3')
1844+
self.assertEqualException(f4, 'a=1, a=3, b=4')
1845+
self.assertEqualException(f4, 'a=1, b=2, a=3, b=4')
1846+
self.assertEqualException(f4, 'a=1, a=2, a=3, b=4')
18461847

18471848
# issue #20816: getcallargs() fails to iterate over non-existent
18481849
# kwonlydefaults and raises a wrong TypeError
@@ -2872,8 +2873,6 @@ def foo(cls, *, arg):
28722873
def test_signature_on_partial(self):
28732874
from functools import partial
28742875

2875-
Parameter = inspect.Parameter
2876-
28772876
def test():
28782877
pass
28792878

@@ -2988,8 +2987,6 @@ def test(a, b, c:int) -> 42:
29882987
((('c', ..., int, "positional_or_keyword"),),
29892988
42))
29902989

2991-
psig = inspect.signature(partial(partial(test, 1), 2))
2992-
29932990
def foo(a):
29942991
return a
29952992
_foo = partial(partial(foo, a=10), a=20)
@@ -4153,8 +4150,6 @@ def test(a, *args, b, z=100, **kwargs):
41534150
self.assertEqual(ba.args, (10, 20))
41544151

41554152
def test_signature_bind_positional_only(self):
4156-
P = inspect.Parameter
4157-
41584153
def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs):
41594154
return a_po, b_po, c_po, foo, bar, kwargs
41604155

@@ -4578,7 +4573,6 @@ def test_qualname_source(self):
45784573
self.assertEqual(err, b'')
45794574

45804575
def test_builtins(self):
4581-
module = importlib.import_module('unittest')
45824576
_, out, err = assert_python_failure('-m', 'inspect',
45834577
'sys')
45844578
lines = err.decode().splitlines()

0 commit comments

Comments
 (0)