mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-85294: Handle missing arguments to @singledispatchmethod gracefully (GH-21471)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
5903190727
commit
8b776e0f41
3 changed files with 23 additions and 2 deletions
|
@ -2867,11 +2867,26 @@ class TestSingleDispatch(unittest.TestCase):
|
|||
|
||||
def test_invalid_positional_argument(self):
|
||||
@functools.singledispatch
|
||||
def f(*args):
|
||||
def f(*args, **kwargs):
|
||||
pass
|
||||
msg = 'f requires at least 1 positional argument'
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
f()
|
||||
msg = 'f requires at least 1 positional argument'
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
f(a=1)
|
||||
|
||||
def test_invalid_positional_argument_singledispatchmethod(self):
|
||||
class A:
|
||||
@functools.singledispatchmethod
|
||||
def t(self, *args, **kwargs):
|
||||
pass
|
||||
msg = 't requires at least 1 positional argument'
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
A().t()
|
||||
msg = 't requires at least 1 positional argument'
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
A().t(a=1)
|
||||
|
||||
def test_union(self):
|
||||
@functools.singledispatch
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue