Fix: method Chat.get_member_count usage without argument (#643)

* fix: wrong argument passed to get_member_count()

* fix: not async .close() for aiohttp.ClientResponse

* fix: wrong parameter passed to InputFile

* enh: implement all abstract methods for DisabledStorage

* ref: style fixes
This commit is contained in:
Ramzan Bekbulatov 2021-08-05 22:32:30 +03:00 committed by GitHub
parent 580fa2e499
commit aaf0b42acf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 38 additions and 21 deletions

View file

@ -4,7 +4,7 @@ import typing
import warnings
from contextvars import ContextVar
from dataclasses import dataclass, field
from typing import Any, Dict, Iterable, List, Optional, Union
from typing import Any, Dict, Iterable, Optional, Union
from babel.support import LazyProxy

View file

@ -461,7 +461,6 @@ class DisabledStorage(BaseStorage):
"""
Empty storage. Use it if you don't want to use Finite-State Machine
"""
async def close(self):
pass
@ -499,6 +498,25 @@ class DisabledStorage(BaseStorage):
data: typing.Dict = None):
self._warn()
async def get_bucket(self, *,
chat: typing.Union[str, int, None] = None,
user: typing.Union[str, int, None] = None,
default: typing.Optional[dict] = None) -> typing.Dict:
self._warn()
return {}
async def set_bucket(self, *,
chat: typing.Union[str, int, None] = None,
user: typing.Union[str, int, None] = None,
bucket: typing.Dict = None):
self._warn()
async def update_bucket(self, *,
chat: typing.Union[str, int, None] = None,
user: typing.Union[str, int, None] = None,
bucket: typing.Dict = None, **kwargs):
self._warn()
@staticmethod
def _warn():
warn(f"You havent set any storage yet so no states and no data will be saved. \n"

View file

@ -78,7 +78,7 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
Abstract class for telegram objects
"""
def __init__(self, conf: typing.Dict[str, typing.Any]=None, **kwargs: typing.Any) -> None:
def __init__(self, conf: typing.Dict[str, typing.Any] = None, **kwargs: typing.Any) -> None:
"""
Deserialize object

View file

@ -12,4 +12,4 @@ class BotCommand(base.TelegramObject):
description: base.String = fields.Field()
def __init__(self, command: base.String, description: base.String):
super(BotCommand, self).__init__(command=command, description=description)
super(BotCommand, self).__init__(command=command, description=description)

View file

@ -497,7 +497,7 @@ class Chat(base.TelegramObject):
async def get_members_count(self) -> base.Integer:
"""Renamed to get_member_count."""
return await self.get_member_count(self.id)
return await self.get_member_count()
async def get_member(self, user_id: base.Integer) -> ChatMember:
"""

View file

@ -5,7 +5,7 @@ import logging
import os
import secrets
from pathlib import Path
from typing import Union
from typing import Union, Optional
import aiohttp
@ -27,7 +27,7 @@ class InputFile(base.TelegramObject):
https://core.telegram.org/bots/api#inputfile
"""
def __init__(self, path_or_bytesio: Union[str, io.IOBase, Path], filename=None, conf=None):
def __init__(self, path_or_bytesio: Union[str, io.IOBase, Path, '_WebPipe'], filename=None, conf=None):
"""
:param path_or_bytesio:
@ -118,7 +118,7 @@ class InputFile(base.TelegramObject):
if filename is None:
filename = pipe.name
return cls(pipe, filename, chunk_size)
return cls(pipe, filename)
def save(self, filename, chunk_size=CHUNK_SIZE):
"""
@ -159,8 +159,8 @@ class _WebPipe:
self.url = url
self.chunk_size = chunk_size
self._session: aiohttp.ClientSession = None
self._response: aiohttp.ClientResponse = None
self._session: Optional[aiohttp.ClientSession] = None
self._response: Optional[aiohttp.ClientResponse] = None
self._reader = None
self._name = None
@ -182,7 +182,7 @@ class _WebPipe:
async def close(self):
if self._response and not self._response.closed:
await self._response.close()
self._response.close()
if self._session and not self._session.closed:
await self._session.close()
if self._lock.locked():

View file

@ -3039,10 +3039,10 @@ class ContentType(helper.Helper):
GROUP_CHAT_CREATED = helper.Item() # group_chat_created
PASSPORT_DATA = helper.Item() # passport_data
PROXIMITY_ALERT_TRIGGERED = helper.Item() # proximity_alert_triggered
VOICE_CHAT_SCHEDULED = helper.Item() # voice_chat_scheduled
VOICE_CHAT_STARTED = helper.Item() # voice_chat_started
VOICE_CHAT_ENDED = helper.Item() # voice_chat_ended
VOICE_CHAT_PARTICIPANTS_INVITED = helper.Item() # voice_chat_participants_invited
VOICE_CHAT_SCHEDULED = helper.Item() # voice_chat_scheduled
VOICE_CHAT_STARTED = helper.Item() # voice_chat_started
VOICE_CHAT_ENDED = helper.Item() # voice_chat_ended
VOICE_CHAT_PARTICIPANTS_INVITED = helper.Item() # voice_chat_participants_invited
UNKNOWN = helper.Item() # unknown
ANY = helper.Item() # any

View file

@ -48,12 +48,12 @@ class MessageEntity(base.TelegramObject):
:return: part of text
"""
if sys.maxunicode == 0xFFFF:
return text[self.offset : self.offset + self.length]
return text[self.offset: self.offset + self.length]
entity_text = (
text.encode("utf-16-le") if not isinstance(text, bytes) else text
)
entity_text = entity_text[self.offset * 2 : (self.offset + self.length) * 2]
entity_text = entity_text[self.offset * 2: (self.offset + self.length) * 2]
return entity_text.decode("utf-16-le")
@deprecated(

View file

@ -129,7 +129,9 @@ class KeyboardButton(base.TelegramObject):
class ReplyKeyboardRemove(base.TelegramObject):
"""
Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup).
Upon receiving a message with this object, Telegram clients will remove the current custom keyboard
and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot.
An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup).
https://core.telegram.org/bots/api#replykeyboardremove
"""

View file

@ -41,8 +41,6 @@ class Sticker(base.TelegramObject, mixins.Downloadable):
Source: https://core.telegram.org/bots/api#deletestickerfromset
:param sticker: File identifier of the sticker
:type sticker: :obj:`base.String`
:return: Returns True on success
:rtype: :obj:`base.Boolean`
"""

View file

@ -2,7 +2,6 @@ from datetime import datetime
from . import base
from . import fields
from .user import User
class VoiceChatScheduled(base.TelegramObject):