gh-90795: Fix error message incorrectly including "positional" by StanFromIreland · Pull Request #139678 · python/cpython · GitHub
Skip to content
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
28 changes: 20 additions & 8 deletions Lib/inspect.py
2 changes: 1 addition & 1 deletion Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ def check_raises_type_error(self, message):
self.assertEqual(str(cm.exception), message)

def test_missing_arguments(self):
msg = "A.method_two_args() missing 1 required positional argument: 'y'"
msg = "A.method_two_args() missing 1 required argument: 'y'"
with self.check_raises_type_error(msg):
A().method_two_args("x")

Expand Down
18 changes: 9 additions & 9 deletions Lib/test/test_dataclasses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ class C:

with self.assertRaisesRegex(TypeError,
r"__init__\(\) missing 1 required "
"positional argument: 'x'"):
"argument: 'x'"):
C()

def test_field_default(self):
Expand Down Expand Up @@ -935,7 +935,7 @@ class C:
x: int=field(default=MISSING)
with self.assertRaisesRegex(TypeError,
r'__init__\(\) missing 1 required '
'positional argument'):
'argument'):
C()
self.assertNotIn('x', C.__dict__)

Expand All @@ -944,7 +944,7 @@ class D:
x: int
with self.assertRaisesRegex(TypeError,
r'__init__\(\) missing 1 required '
'positional argument'):
'argument'):
D()
self.assertNotIn('x', D.__dict__)

Expand All @@ -957,7 +957,7 @@ class C:
x: int=field(default_factory=MISSING)
with self.assertRaisesRegex(TypeError,
r'__init__\(\) missing 1 required '
'positional argument'):
'argument'):
C()
self.assertNotIn('x', C.__dict__)

Expand All @@ -966,7 +966,7 @@ class D:
x: int=field(default=MISSING, default_factory=MISSING)
with self.assertRaisesRegex(TypeError,
r'__init__\(\) missing 1 required '
'positional argument'):
'argument'):
D()
self.assertNotIn('x', D.__dict__)

Expand Down Expand Up @@ -3260,7 +3260,7 @@ class C:
# also have a default value (of type
# types.MemberDescriptorType).
with self.assertRaisesRegex(TypeError,
r"__init__\(\) missing 1 required positional argument: 'x'"):
r"__init__\(\) missing 1 required argument: 'x'"):
C()

# We can create an instance, and assign to x.
Expand Down Expand Up @@ -3784,7 +3784,7 @@ def __init_subclass__(cls, arg):

with self.assertRaisesRegex(
TypeError,
"missing 1 required positional argument: 'arg'",
"missing 1 required argument: 'arg'",
):
@dataclass(slots=True)
class WithWrongSuper(WrongSuper, arg=1):
Expand Down Expand Up @@ -4018,7 +4018,7 @@ def __set__(self, instance: Any, value: int) -> None:
class C:
i: D = D()

with self.assertRaisesRegex(TypeError, 'missing 1 required positional argument'):
with self.assertRaisesRegex(TypeError, 'missing 1 required argument'):
c = C()

class TestStringAnnotations(unittest.TestCase):
Expand Down Expand Up @@ -4227,7 +4227,7 @@ class Base2:
C = make_dataclass('C',
[('y', int)],
bases=(Base1, Base2))
with self.assertRaisesRegex(TypeError, 'required positional'):
with self.assertRaisesRegex(TypeError, 'required argument'):
c = C(2)
c = C(1, 2)
self.assertIsInstance(c, C)
Expand Down
16 changes: 8 additions & 8 deletions Lib/test/test_extcall.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@
>>> g()
Traceback (most recent call last):
...
TypeError: g() missing 1 required positional argument: 'x'
TypeError: g() missing 1 required argument: 'x'

>>> g(*())
Traceback (most recent call last):
...
TypeError: g() missing 1 required positional argument: 'x'
TypeError: g() missing 1 required argument: 'x'

>>> g(*(), **{})
Traceback (most recent call last):
...
TypeError: g() missing 1 required positional argument: 'x'
TypeError: g() missing 1 required argument: 'x'

>>> g(1)
1 () {}
Expand Down Expand Up @@ -505,27 +505,27 @@
>>> f()
Traceback (most recent call last):
...
TypeError: f() missing 1 required positional argument: 'a'
TypeError: f() missing 1 required argument: 'a'
>>> def f(a, b): pass
>>> f()
Traceback (most recent call last):
...
TypeError: f() missing 2 required positional arguments: 'a' and 'b'
TypeError: f() missing 2 required arguments: 'a' and 'b'
>>> def f(a, b, c): pass
>>> f()
Traceback (most recent call last):
...
TypeError: f() missing 3 required positional arguments: 'a', 'b', and 'c'
TypeError: f() missing 3 required arguments: 'a', 'b', and 'c'
>>> def f(a, b, c, d, e): pass
>>> f()
Traceback (most recent call last):
...
TypeError: f() missing 5 required positional arguments: 'a', 'b', 'c', 'd', and 'e'
TypeError: f() missing 5 required arguments: 'a', 'b', 'c', 'd', and 'e'
>>> def f(a, b=4, c=5, d=5): pass
>>> f(c=12, b=9)
Traceback (most recent call last):
...
TypeError: f() missing 1 required positional argument: 'a'
TypeError: f() missing 1 required argument: 'a'

Same with keyword only args:

Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_positional_only_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def f(a, b, /):
def test_positional_only_and_arg_invalid_calls(self):
def f(a, b, /, c):
pass
with self.assertRaisesRegex(TypeError, r"f\(\) missing 1 required positional argument: 'c'"):
with self.assertRaisesRegex(TypeError, r"f\(\) missing 1 required argument: 'c'"):
f(1, 2)
with self.assertRaisesRegex(TypeError, r"f\(\) missing 2 required positional arguments: 'b' and 'c'"):
f(1)
Expand Down Expand Up @@ -170,7 +170,7 @@ def f(a, b, /, c, *, d, e):
f(1, 2, 3, e=2)
with self.assertRaisesRegex(TypeError, r"missing 2 required keyword-only arguments: 'd' and 'e'"):
f(1, 2, 3)
with self.assertRaisesRegex(TypeError, r"f\(\) missing 1 required positional argument: 'c'"):
with self.assertRaisesRegex(TypeError, r"f\(\) missing 1 required argument: 'c'"):
f(1, 2)
with self.assertRaisesRegex(TypeError, r"f\(\) missing 2 required positional arguments: 'b' and 'c'"):
f(1)
Expand Down Expand Up @@ -278,7 +278,7 @@ def g(x2,/,y2):
return g

self.assertEqual(f(1,2)(3,4), 10)
with self.assertRaisesRegex(TypeError, r"g\(\) missing 1 required positional argument: 'y2'"):
with self.assertRaisesRegex(TypeError, r"g\(\) missing 1 required argument: 'y2'"):
f(1,2)(3)
with self.assertRaisesRegex(TypeError, r"g\(\) takes 2 positional arguments but 3 were given"):
f(1,2)(3,4,5)
Expand All @@ -296,7 +296,7 @@ def g(x2,/,y2):
return g

self.assertEqual(f(1,2)(3,4), 10)
with self.assertRaisesRegex(TypeError, r"g\(\) missing 1 required positional argument: 'y2'"):
with self.assertRaisesRegex(TypeError, r"g\(\) missing 1 required argument: 'y2'"):
f(1,2)(3)
with self.assertRaisesRegex(TypeError, r"g\(\) takes 2 positional arguments but 3 were given"):
f(1,2)(3,4,5)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an error message that incorrectly specified a missing argument as
"positional" in function calls.
49 changes: 41 additions & 8 deletions Python/ceval.c
Loading