Fix the ability to copy the state, now copying the state will return the same state.

This commit is contained in:
darksidecat 2022-06-19 01:39:11 +03:00
parent adfc89f125
commit eeacd1019a
3 changed files with 19 additions and 0 deletions

1
CHANGES/927.bugfix.rst Normal file
View file

@ -0,0 +1 @@
Fixed the ability to copy the state, now copying the state will return the same state.

View file

@ -54,6 +54,12 @@ class State:
return True
return raw_state == self.state
def __copy__(self):
return self
def __deepcopy__(self, memo=None):
return self
class StatesGroupMeta(type):
__parent__: "Optional[Type[StatesGroup]]"

View file

@ -1,3 +1,4 @@
from copy import deepcopy, copy
from inspect import isclass
import pytest
@ -50,3 +51,14 @@ class TestStateFilter:
async def test_filter(self, state, current_state, result):
f = StateFilter(state=state)
assert bool(await f(obj=Update(update_id=42), raw_state=current_state)) is result
@pytestmark
async def test_state_copy(self):
class SG(StatesGroup):
state = State()
assert SG.state is deepcopy(SG.state)
assert SG.state is copy(SG.state)
assert SG is copy(SG)
assert SG is deepcopy(SG)