From 91b665ea9496dd6b18ee4cf391ce54305b66cc6b Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sun, 15 May 2022 00:59:35 +0300 Subject: [PATCH] Poll type parameter parse fix Plus some typo --- .github/PULL_REQUEST_TEMPLATE.md | 5 ++--- telebot/asyncio_storage/redis_storage.py | 6 +++--- telebot/storage/redis_storage.py | 6 +++--- telebot/types.py | 14 ++++++++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index b46f5a6..a34f405 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -10,6 +10,5 @@ OS: ## Checklist: - [ ] I added/edited example on new feature/change (if exists) -- [ ] My changes won't break backend compatibility -- [ ] I made changes for async and sync - +- [ ] My changes won't break backward compatibility +- [ ] I made changes both for sync and async diff --git a/telebot/asyncio_storage/redis_storage.py b/telebot/asyncio_storage/redis_storage.py index 0cf52b9..e31ddb0 100644 --- a/telebot/asyncio_storage/redis_storage.py +++ b/telebot/asyncio_storage/redis_storage.py @@ -35,7 +35,7 @@ class StateRedisStorage(StateStorageBase): """ Function to get record from database. It has nothing to do with states. - Made for backend compatibility + Made for backward compatibility """ result = await self.redis.get(self.prefix+str(key)) if result: return json.loads(result) @@ -45,7 +45,7 @@ class StateRedisStorage(StateStorageBase): """ Function to set record to database. It has nothing to do with states. - Made for backend compatibility + Made for backward compatibility """ await self.redis.set(self.prefix+str(key), json.dumps(value)) @@ -55,7 +55,7 @@ class StateRedisStorage(StateStorageBase): """ Function to delete record from database. It has nothing to do with states. - Made for backend compatibility + Made for backward compatibility """ await self.redis.delete(self.prefix+str(key)) return True diff --git a/telebot/storage/redis_storage.py b/telebot/storage/redis_storage.py index cd40587..2a5fb4a 100644 --- a/telebot/storage/redis_storage.py +++ b/telebot/storage/redis_storage.py @@ -28,7 +28,7 @@ class StateRedisStorage(StateStorageBase): """ Function to get record from database. It has nothing to do with states. - Made for backend compatibility + Made for backward compatibility """ connection = Redis(connection_pool=self.redis) result = connection.get(self.prefix+str(key)) @@ -40,7 +40,7 @@ class StateRedisStorage(StateStorageBase): """ Function to set record to database. It has nothing to do with states. - Made for backend compatibility + Made for backward compatibility """ connection = Redis(connection_pool=self.redis) connection.set(self.prefix+str(key), json.dumps(value)) @@ -51,7 +51,7 @@ class StateRedisStorage(StateStorageBase): """ Function to delete record from database. It has nothing to do with states. - Made for backend compatibility + Made for backward compatibility """ connection = Redis(connection_pool=self.redis) connection.delete(self.prefix+str(key)) diff --git a/telebot/types.py b/telebot/types.py index 9793417..ff08fc6 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -2774,23 +2774,29 @@ class Poll(JsonDeserializable): obj['explanation_entities'] = Message.parse_entities(obj['explanation_entities']) return cls(**obj) + # noinspection PyShadowingBuiltins def __init__( self, question, options, - poll_id=None, total_voter_count=None, is_closed=None, is_anonymous=None, poll_type=None, + poll_id=None, total_voter_count=None, is_closed=None, is_anonymous=None, type=None, allows_multiple_answers=None, correct_option_id=None, explanation=None, explanation_entities=None, - open_period=None, close_date=None, **kwargs): + open_period=None, close_date=None, poll_type=None, **kwargs): self.id: str = poll_id self.question: str = question self.options: List[PollOption] = options self.total_voter_count: int = total_voter_count self.is_closed: bool = is_closed self.is_anonymous: bool = is_anonymous - self.type: str = poll_type + self.type: str = type + if poll_type is not None: + # Wrong param name backward compatibility + logger.warning("Poll: poll_type parameter is deprecated. Use type instead.") + if type is None: + self.type: str = poll_type self.allows_multiple_answers: bool = allows_multiple_answers self.correct_option_id: int = correct_option_id self.explanation: str = explanation - self.explanation_entities: List[MessageEntity] = explanation_entities # Default state of entities is None. if (explanation_entities is not None) else [] + self.explanation_entities: List[MessageEntity] = explanation_entities self.open_period: int = open_period self.close_date: int = close_date