mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-33197: Update a error message of invalid inspect.Parameters. (GH-6636) (GH-7204)
(cherry picked from commit a9cab433bb
)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
This commit is contained in:
parent
441afbd9c3
commit
cb055bcc2b
3 changed files with 55 additions and 19 deletions
|
@ -1444,6 +1444,20 @@ class TestGetcallargsFunctions(unittest.TestCase):
|
|||
with self.assertRaisesRegex(TypeError, "'a', 'b' and 'c'"):
|
||||
inspect.getcallargs(f6)
|
||||
|
||||
# bpo-33197
|
||||
with self.assertRaisesRegex(ValueError,
|
||||
'variadic keyword parameters cannot'
|
||||
' have default values'):
|
||||
inspect.Parameter("foo", kind=inspect.Parameter.VAR_KEYWORD,
|
||||
default=42)
|
||||
with self.assertRaisesRegex(ValueError,
|
||||
"value 5 is not a valid Parameter.kind"):
|
||||
inspect.Parameter("bar", kind=5, default=42)
|
||||
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'name must be a str, not a int'):
|
||||
inspect.Parameter(123, kind=4)
|
||||
|
||||
class TestGetcallargsMethods(TestGetcallargsFunctions):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -3044,7 +3058,8 @@ class TestParameterObject(unittest.TestCase):
|
|||
self.assertIs(p.annotation, p.empty)
|
||||
self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)
|
||||
|
||||
with self.assertRaisesRegex(ValueError, 'invalid value'):
|
||||
with self.assertRaisesRegex(ValueError, "value '123' is "
|
||||
"not a valid Parameter.kind"):
|
||||
inspect.Parameter('foo', default=10, kind='123')
|
||||
|
||||
with self.assertRaisesRegex(ValueError, 'not a valid parameter name'):
|
||||
|
@ -3134,7 +3149,9 @@ class TestParameterObject(unittest.TestCase):
|
|||
self.assertEqual(p2.kind, p2.POSITIONAL_OR_KEYWORD)
|
||||
self.assertNotEqual(p2, p)
|
||||
|
||||
with self.assertRaisesRegex(ValueError, 'invalid value for'):
|
||||
with self.assertRaisesRegex(ValueError,
|
||||
"value <class 'inspect._empty'> "
|
||||
"is not a valid Parameter.kind"):
|
||||
p2 = p2.replace(kind=p2.empty)
|
||||
|
||||
p2 = p2.replace(kind=p2.KEYWORD_ONLY)
|
||||
|
@ -3147,7 +3164,9 @@ class TestParameterObject(unittest.TestCase):
|
|||
@cpython_only
|
||||
def test_signature_parameter_implicit(self):
|
||||
with self.assertRaisesRegex(ValueError,
|
||||
'implicit arguments must be passed in as'):
|
||||
'implicit arguments must be passed as '
|
||||
'positional or keyword arguments, '
|
||||
'not positional-only'):
|
||||
inspect.Parameter('.0', kind=inspect.Parameter.POSITIONAL_ONLY)
|
||||
|
||||
param = inspect.Parameter(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue