blob: ef44f71c15cd9f870e65b4fe2757b47a2edb7b1d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
"""Tests for singledispatchmethod-function"""
# pylint: disable=missing-class-docstring, missing-function-docstring,too-few-public-methods
from functools import singledispatch, singledispatchmethod
class BoardRight:
@singledispatch
@staticmethod
def convert_position(position):
pass
@convert_position.register
@staticmethod
def _(position: str) -> tuple:
position_a, position_b = position.split(",")
return (int(position_a), int(position_b))
@convert_position.register
@staticmethod
def _(position: tuple) -> str:
return f"{position[0]},{position[1]}"
class Board:
@singledispatchmethod # [singledispatchmethod-function]
@staticmethod
def convert_position(position):
pass
@convert_position.register # [singledispatchmethod-function]
@staticmethod
def _(position: str) -> tuple:
position_a, position_b = position.split(",")
return (int(position_a), int(position_b))
@convert_position.register # [singledispatchmethod-function]
@staticmethod
def _(position: tuple) -> str:
return f"{position[0]},{position[1]}"
|