Skip to content

Commit 606708a

Browse files
committed
Use fully qualified type names more consistently, more msg = in tests
1 parent fa270ff commit 606708a

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

Lib/test/test_ast/test_ast.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def test_field_attr_writable(self):
458458
self.assertEqual(x._fields, 666)
459459

460460
def test_classattrs(self):
461-
msg = "Constant.__init__ missing 1 required positional argument: 'value'"
461+
msg = "ast.Constant.__init__ missing 1 required positional argument: 'value'"
462462
with self.assertRaisesRegex(TypeError, re.escape(msg)):
463463
x = ast.Constant()
464464

@@ -485,11 +485,12 @@ def test_classattrs(self):
485485
self.assertRaises(TypeError, ast.Constant, 1, None, 2, lineno=0)
486486

487487
# Arbitrary keyword arguments are not supported
488-
msg = "Constant.__init__ got an unexpected keyword argument 'foo'"
488+
msg = "ast.Constant.__init__ got an unexpected keyword argument 'foo'"
489489
with self.assertRaisesRegex(TypeError, re.escape(msg)):
490490
ast.Constant(1, foo='bar')
491491

492-
with self.assertRaisesRegex(TypeError, "Constant got multiple values for argument 'value'"):
492+
msg = "ast.Constant got multiple values for argument 'value'"
493+
with self.assertRaisesRegex(TypeError, re.escape(msg)):
493494
ast.Constant(1, value=2)
494495

495496
self.assertEqual(ast.Constant(42).value, 42)
@@ -529,7 +530,7 @@ def test_module(self):
529530

530531
def test_nodeclasses(self):
531532
# Zero arguments constructor is not allowed
532-
msg = "missing 3 required positional arguments: 'left', 'op', and 'right'"
533+
msg = "ast.BinOp.__init__ missing 3 required positional arguments: 'left', 'op', and 'right'"
533534
with self.assertRaisesRegex(TypeError, re.escape(msg)):
534535
x = ast.BinOp()
535536

@@ -3211,8 +3212,8 @@ def test_FunctionDef(self):
32113212
args = ast.arguments()
32123213
self.assertEqual(args.args, [])
32133214
self.assertEqual(args.posonlyargs, [])
3214-
with self.assertRaisesRegex(TypeError,
3215-
r"FunctionDef\.__init__ missing 1 required positional argument: 'name'"):
3215+
msg = "ast.FunctionDef.__init__ missing 1 required positional argument: 'name'"
3216+
with self.assertRaisesRegex(TypeError, re.escape(msg)):
32163217
node = ast.FunctionDef(args=args)
32173218

32183219
node = ast.FunctionDef(name='foo', args=args)
@@ -3232,8 +3233,8 @@ def test_expr_context(self):
32323233
self.assertEqual(name3.id, "x")
32333234
self.assertIsInstance(name3.ctx, ast.Del)
32343235

3235-
with self.assertRaisesRegex(TypeError,
3236-
r"Name\.__init__ missing 1 required positional argument: 'id'"):
3236+
msg = "ast.Name.__init__ missing 1 required positional argument: 'id'"
3237+
with self.assertRaisesRegex(TypeError, re.escape(msg)):
32373238
name3 = ast.Name()
32383239

32393240
def test_custom_subclass_with_no_fields(self):

Parser/asdl_c.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,8 @@ def visitModule(self, mod):
10061006
}
10071007
if (p == 0) {
10081008
PyErr_Format(PyExc_TypeError,
1009-
"%.400s got multiple values for argument '%U'",
1010-
Py_TYPE(self)->tp_name, key);
1009+
"%T got multiple values for argument '%U'",
1010+
self, key);
10111011
res = -1;
10121012
goto cleanup;
10131013
}

Python/Python-ast.c

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)