Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion compiler/api/template/combinator.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class {name}(TLObject): # type: ignore
{read_types}
return {name}({return_arguments})

def write(self, *args) -> bytes:
def write(self, *args: Any) -> bytes:
b = BytesIO()
b.write(Int(self.ID, False))

Expand Down
2 changes: 1 addition & 1 deletion compiler/api/template/type.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class {name}: # type: ignore

QUALNAME = "pyrogram.raw.base.{qualname}"

def __init__(self):
def __init__(self) -> None:
raise TypeError("Base types can only be used for type checking purposes: "
"you tried to use a base type instance as argument, "
"but you need to instantiate one of its constructors instead. "
Expand Down
13 changes: 7 additions & 6 deletions pyrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
from io import StringIO, BytesIO
from mimetypes import MimeTypes
from pathlib import Path
from typing import Union, List, Optional, Callable, AsyncGenerator, Type, Tuple
from typing import Any, Union, List, Optional, Callable, AsyncGenerator, Type, Tuple, Optional


import pyrogram
from pyrogram import __version__, __license__
Expand Down Expand Up @@ -271,7 +272,7 @@ def __init__(
init_connection_params: Optional["raw.base.JSONValue"] = None,
connection_factory: Type[Connection] = Connection,
protocol_factory: Type[TCP] = TCPAbridged
):
) -> None:
super().__init__()

self.name = name
Expand Down Expand Up @@ -345,7 +346,7 @@ def __init__(

self.takeout_id = None

self.disconnect_handler = None
self.disconnect_handler: Union[Callable[["Client"], Any], None] = None

self.me: Optional[User] = None

Expand Down Expand Up @@ -1012,8 +1013,8 @@ async def get_file(
file_size: int = 0,
limit: int = 0,
offset: int = 0,
progress: Callable = None,
progress_args: tuple = ()
progress: Optional[Callable[[int, int], Any]] = None,
progress_args: Tuple[Any, ...] = ()
) -> AsyncGenerator[bytes, None]:
async with self.get_file_semaphore:
file_type = file_id.file_type
Expand Down Expand Up @@ -1242,7 +1243,7 @@ def guess_extension(self, mime_type: str) -> Optional[str]:


class Cache:
def __init__(self, capacity: int):
def __init__(self, capacity: int) -> None:
self.capacity = capacity
self.store = {}

Expand Down
9 changes: 5 additions & 4 deletions pyrogram/crypto/aes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
from typing import Optional

log = logging.getLogger(__name__)

Expand All @@ -34,11 +35,11 @@ def ige256_decrypt(data: bytes, key: bytes, iv: bytes) -> bytes:
return tgcrypto.ige256_decrypt(data, key, iv)


def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: Optional[bytearray] = None) -> bytes:
return tgcrypto.ctr256_encrypt(data, key, iv, state or bytearray(1))


def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: Optional[bytearray] = None) -> bytes:
return tgcrypto.ctr256_decrypt(data, key, iv, state or bytearray(1))


Expand Down Expand Up @@ -66,11 +67,11 @@ def ige256_decrypt(data: bytes, key: bytes, iv: bytes) -> bytes:
return ige(data, key, iv, False)


def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: Optional[bytearray] = None) -> bytes:
return ctr(data, key, iv, state or bytearray(1))


def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: Optional[bytearray] = None) -> bytes:
return ctr(data, key, iv, state or bytearray(1))


Expand Down
6 changes: 4 additions & 2 deletions pyrogram/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import inspect
import logging
from collections import OrderedDict
from typing import Any, Dict, List

import pyrogram
from pyrogram import utils
Expand All @@ -29,6 +30,7 @@
ChosenInlineResultHandler, ChatMemberUpdatedHandler, ChatJoinRequestHandler, StoryHandler,
ShippingQueryHandler, MessageReactionHandler, MessageReactionCountHandler, ChatBoostHandler, PurchasedPaidMediaHandler
)
from pyrogram.handlers.handler import Handler
from pyrogram.raw.types import (
UpdateNewMessage, UpdateNewChannelMessage, UpdateNewScheduledMessage,
UpdateBotNewBusinessMessage, UpdateBotEditBusinessMessage, UpdateBotDeleteBusinessMessage,
Expand Down Expand Up @@ -64,15 +66,15 @@ class Dispatcher:
CHAT_BOOST_UPDATES = (UpdateBotChatBoost,)
PURCHASED_PAID_MEDIA_UPDATES = (UpdateBotPurchasedPaidMedia,)

def __init__(self, client: "pyrogram.Client"):
def __init__(self, client: "pyrogram.Client") -> None:
self.client = client
self.loop = asyncio.get_event_loop()

self.handler_worker_tasks = []
self.locks_list = []

self.updates_queue = asyncio.Queue()
self.groups = OrderedDict()
self.groups: Dict[int, List[Handler[Any]]] = OrderedDict()

async def message_parser(update, users, chats):
connection_id = getattr(update, "connection_id", None)
Expand Down
7 changes: 4 additions & 3 deletions pyrogram/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Optional
from .exceptions import *
from .rpc_error import UnknownError

Expand All @@ -36,7 +37,7 @@ class BadMsgNotification(Exception):
64: "Invalid container."
}

def __init__(self, code):
def __init__(self, code) -> None:
description = self.descriptions.get(code, "Unknown error code")
super().__init__(f"[{code}] {description}")

Expand All @@ -54,12 +55,12 @@ def check(cls, cond: bool, msg: str):
class SecurityCheckMismatch(SecurityError):
"""Raised when a security check mismatch occurs."""

def __init__(self, msg: str = None):
def __init__(self, msg: Optional[str] = None) -> None:
super().__init__("A security check mismatch has occurred." if msg is None else msg)


class CDNFileHashMismatch(SecurityError):
"""Raised when a CDN file hash mismatch occurs."""

def __init__(self, msg: str = None):
def __init__(self, msg: Optional[str] = None) -> None:
super().__init__("A CDN file hash mismatch has occurred." if msg is None else msg)
8 changes: 4 additions & 4 deletions pyrogram/errors/rpc_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import re
from datetime import datetime
from importlib import import_module
from typing import Type, Union
from typing import Type, Union, Optional

from pyrogram import raw
from pyrogram.raw.core import TLObject
Expand All @@ -34,11 +34,11 @@ class RPCError(Exception):

def __init__(
self,
value: Union[int, str, raw.types.RpcError] = None,
rpc_name: str = None,
value: Union[int, str, raw.types.RpcError, None] = None,
rpc_name: Optional[str] = None,
is_unknown: bool = False,
is_signed: bool = False
):
) -> None:
super().__init__("Telegram says: [{}{} {}] - {} {}".format(
"-" if is_signed else "",
self.CODE,
Expand Down
40 changes: 20 additions & 20 deletions pyrogram/file_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import struct
from enum import IntEnum
from io import BytesIO
from typing import List
from typing import List, Optional

from pyrogram.raw.core import Bytes, String

Expand Down Expand Up @@ -163,20 +163,20 @@ def __init__(
file_type: FileType,
dc_id: int,
file_reference: bytes = b"",
url: str = None,
media_id: int = None,
access_hash: int = None,
volume_id: int = None,
thumbnail_source: ThumbnailSource = None,
thumbnail_file_type: FileType = None,
url: Optional[str] = None,
media_id: Optional[int] = None,
access_hash: Optional[int] = None,
volume_id: Optional[int] = None,
thumbnail_source: Optional[ThumbnailSource] = None,
thumbnail_file_type: Optional[FileType] = None,
thumbnail_size: str = "",
secret: int = None,
local_id: int = None,
chat_id: int = None,
chat_access_hash: int = None,
sticker_set_id: int = None,
sticker_set_access_hash: int = None
):
secret: Optional[int] = None,
local_id: Optional[int] = None,
chat_id: Optional[int] = None,
chat_access_hash: Optional[int] = None,
sticker_set_id: Optional[int] = None,
sticker_set_access_hash: Optional[int] = None
) -> None:
self.major = major
self.minor = minor
self.file_type = file_type
Expand Down Expand Up @@ -337,7 +337,7 @@ def decode(file_id: str):
access_hash=access_hash
)

def encode(self, *, major: int = None, minor: int = None):
def encode(self, *, major: Optional[int] = None, minor: Optional[int] = None):
major = major if major is not None else self.major
minor = minor if minor is not None else self.minor

Expand Down Expand Up @@ -415,11 +415,11 @@ class FileUniqueId:
def __init__(
self, *,
file_unique_type: FileUniqueType,
url: str = None,
media_id: int = None,
volume_id: int = None,
local_id: int = None
):
url: Optional[str] = None,
media_id: Optional[int] = None,
volume_id: Optional[int] = None,
local_id: Optional[int] = None
) -> None:
self.file_unique_type = file_unique_type
self.url = url
self.media_id = media_id
Expand Down
Loading