mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
add typehints, tests
This commit is contained in:
parent
7c18036af0
commit
36fb7761c3
2 changed files with 14 additions and 4 deletions
|
|
@ -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], ...]"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue