mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
return False for not equal objects
creating FilterObject use getfullargspec that check State equality with `type` and `object` builtins, raising Error in `__eq__` method of State break this behavior
This commit is contained in:
parent
36fb7761c3
commit
c952a730c2
2 changed files with 7 additions and 4 deletions
|
|
@ -59,7 +59,7 @@ class State:
|
|||
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")
|
||||
return False
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(self.state)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from inspect import isclass
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.dispatcher.event.handler import FilterObject
|
||||
from aiogram.dispatcher.filters import StateFilter
|
||||
from aiogram.dispatcher.fsm.state import State, StatesGroup
|
||||
from aiogram.types import Update
|
||||
|
|
@ -52,6 +53,10 @@ class TestStateFilter:
|
|||
f = StateFilter(state=state)
|
||||
assert bool(await f(obj=Update(update_id=42), raw_state=current_state)) is result
|
||||
|
||||
@pytestmark
|
||||
async def test_create_filter_from_state(self):
|
||||
FilterObject(callback=State(state="state"))
|
||||
|
||||
@pytestmark
|
||||
async def test_state_copy(self):
|
||||
class SG(StatesGroup):
|
||||
|
|
@ -63,9 +68,7 @@ class TestStateFilter:
|
|||
assert "SG:state" == SG.state
|
||||
|
||||
assert State() == State()
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
assert SG.state == 1
|
||||
assert not 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