add typehints, tests

This commit is contained in:
darksidecat 2022-06-26 13:57:17 +03:00
parent 7c18036af0
commit 36fb7761c3
2 changed files with 14 additions and 4 deletions

View file

@ -1,5 +1,5 @@
import inspect
from typing import Any, Dict, Iterator, Optional, Tuple, Type, no_type_check
from typing import Any, Iterator, Optional, Tuple, Type, no_type_check
from ...types import TelegramObject
@ -54,18 +54,17 @@ class State:
return True
return raw_state == self.state
def __eq__(self, other):
def __eq__(self, other: Any) -> bool:
if isinstance(other, self.__class__):
return self.state == other.state
if isinstance(other, str):
return self.state == other
raise ValueError(f"Comparing {type(self)} and {type(other)} is not supported")
def __hash__(self):
def __hash__(self) -> int:
return hash(self.state)
class StatesGroupMeta(type):
__parent__: "Optional[Type[StatesGroup]]"
__childs__: "Tuple[Type[StatesGroup], ...]"

View file

@ -58,3 +58,14 @@ class TestStateFilter:
state = State()
assert SG.state == copy(SG.state)
assert SG.state == "SG:state"
assert "SG:state" == SG.state
assert State() == State()
with pytest.raises(ValueError):
assert SG.state == 1
states = {SG.state: "OK"}
assert states.get(copy(SG.state)) == "OK"