diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2021-10-20 20:55:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-20 20:55:46 -0700 |
commit | c52338fc42353e8d0c6214e4c22427807439dfd5 (patch) | |
tree | 6da4bf5da5eb739aa48eab1850218d5726c45b10 /Lib/test/test_functools.py | |
parent | 8f05ffb0534c2343fc45ad0e1d91ae1dc2d92b64 (diff) | |
parent | 2a9ab75af32b1ee9f210ae2a0718990687d0f79d (diff) | |
download | cpython-git-enum-private-310.tar.gz |
Merge branch '3.10' into enum-private-310enum-private-310
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r-- | Lib/test/test_functools.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index fece8256a3..bdb4ddcc60 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -2437,6 +2437,48 @@ class TestSingleDispatch(unittest.TestCase): self.assertEqual(a.t(''), "str") self.assertEqual(a.t(0.0), "base") + def test_staticmethod_type_ann_register(self): + class A: + @functools.singledispatchmethod + @staticmethod + def t(arg): + return arg + @t.register + @staticmethod + def _(arg: int): + return isinstance(arg, int) + @t.register + @staticmethod + def _(arg: str): + return isinstance(arg, str) + a = A() + + self.assertTrue(A.t(0)) + self.assertTrue(A.t('')) + self.assertEqual(A.t(0.0), 0.0) + + def test_classmethod_type_ann_register(self): + class A: + def __init__(self, arg): + self.arg = arg + + @functools.singledispatchmethod + @classmethod + def t(cls, arg): + return cls("base") + @t.register + @classmethod + def _(cls, arg: int): + return cls("int") + @t.register + @classmethod + def _(cls, arg: str): + return cls("str") + + self.assertEqual(A.t(0).arg, "int") + self.assertEqual(A.t('').arg, "str") + self.assertEqual(A.t(0.0).arg, "base") + def test_invalid_registrations(self): msg_prefix = "Invalid first argument to `register()`: " msg_suffix = ( |