mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 12:59:46 +00:00
Enable and use ruff
This commit is contained in:
@@ -31,6 +31,7 @@ dev = [
|
||||
"isort~=5.12",
|
||||
"black~=23.3.0",
|
||||
"mypy~=1.3",
|
||||
"ruff~=0.0.292",
|
||||
"pytest~=7.3",
|
||||
"pytest-asyncio~=0.21",
|
||||
]
|
||||
@@ -51,3 +52,8 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
version = {attr = "telethon.version.__version__"}
|
||||
|
||||
[tool.ruff]
|
||||
ignore = [
|
||||
"E501", # formatter takes care of lines that are too long besides documentation
|
||||
]
|
||||
|
@@ -5,6 +5,5 @@ from ._impl import tl as _tl
|
||||
from ._impl.client import Client
|
||||
from ._impl.client.errors import errors
|
||||
from ._impl.mtproto import RpcError
|
||||
from .version import __version__
|
||||
|
||||
__all__ = ["_tl", "Client", "errors", "RpcError"]
|
||||
|
@@ -1,10 +1,8 @@
|
||||
from .bots import InlineResult, InlineResults
|
||||
from .client import Client
|
||||
from .net import Config
|
||||
|
||||
__all__ = [
|
||||
"InlineResult",
|
||||
"InlineResults",
|
||||
"Client",
|
||||
"Config",
|
||||
]
|
||||
|
@@ -4,7 +4,6 @@ from typing import TYPE_CHECKING, AsyncIterator, List, Optional, Self
|
||||
|
||||
from ...tl import abcs, functions, types
|
||||
from ..types import ChatLike, InlineResult, NoPublicConstructor
|
||||
from ..utils import generate_random_id
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .client import Client
|
||||
|
@@ -42,6 +42,7 @@ from ..types import (
|
||||
Draft,
|
||||
File,
|
||||
InFileLike,
|
||||
InlineResult,
|
||||
LoginToken,
|
||||
Message,
|
||||
OutFileLike,
|
||||
@@ -59,7 +60,7 @@ from .auth import (
|
||||
sign_in,
|
||||
sign_out,
|
||||
)
|
||||
from .bots import InlineResult, inline_query
|
||||
from .bots import inline_query
|
||||
from .chats import (
|
||||
get_admin_log,
|
||||
get_participants,
|
||||
@@ -92,7 +93,6 @@ from .messages import (
|
||||
unpin_message,
|
||||
)
|
||||
from .net import (
|
||||
DEFAULT_DC,
|
||||
Config,
|
||||
connect,
|
||||
connected,
|
||||
|
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import math
|
||||
import mimetypes
|
||||
import urllib.parse
|
||||
from inspect import isawaitable
|
||||
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import sys
|
||||
from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Tuple, TypeVar, Union
|
||||
from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Tuple, Union
|
||||
|
||||
from ...session import PackedChat
|
||||
from ...tl import abcs, functions, types
|
||||
|
@@ -12,7 +12,7 @@ from ...mtproto import Full, RpcError
|
||||
from ...mtsender import Sender
|
||||
from ...mtsender import connect as connect_without_auth
|
||||
from ...mtsender import connect_with_auth
|
||||
from ...session import DataCenter, Session
|
||||
from ...session import DataCenter
|
||||
from ...session import User as SessionUser
|
||||
from ...tl import LAYER, Request, functions, types
|
||||
from ..errors import adapt_rpc
|
||||
@@ -154,7 +154,7 @@ async def connect(self: Client) -> None:
|
||||
except RpcError as e:
|
||||
if e.code == 401:
|
||||
self._session.user = None
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
if not self._session.user:
|
||||
|
@@ -130,7 +130,7 @@ async def dispatcher(client: Client) -> None:
|
||||
except asyncio.CancelledError:
|
||||
return
|
||||
except Exception as e:
|
||||
if isinstance(e, RuntimeError) and loop.is_closed:
|
||||
if isinstance(e, RuntimeError) and loop.is_closed():
|
||||
# User probably forgot to call disconnect.
|
||||
logging.warning(
|
||||
"client was not closed cleanly, make sure to call client.disconnect()! %s",
|
||||
|
@@ -50,7 +50,7 @@ def resolved_peer_to_chat(resolved: abcs.contacts.ResolvedPeer) -> Chat:
|
||||
if chat := map.get(peer_id(resolved.peer)):
|
||||
return chat
|
||||
else:
|
||||
raise ValueError(f"no matching chat found in response")
|
||||
raise ValueError("no matching chat found in response")
|
||||
|
||||
|
||||
async def resolve_phone(client: Client, phone: str) -> Chat:
|
||||
|
@@ -3,12 +3,12 @@ from .chat import Channel, Chat, ChatLike, Group, RestrictionReason, User
|
||||
from .dialog import Dialog
|
||||
from .draft import Draft
|
||||
from .file import File, InFileLike, OutFileLike, OutWrapper
|
||||
from .inline_result import InlineResult
|
||||
from .login_token import LoginToken
|
||||
from .message import Message
|
||||
from .meta import NoPublicConstructor
|
||||
from .participant import Participant
|
||||
from .password_token import PasswordToken
|
||||
from .inline_result import InlineResult
|
||||
from .recent_action import RecentAction
|
||||
|
||||
__all__ = [
|
||||
|
@@ -1,7 +1,6 @@
|
||||
from typing import Dict, List, Optional, Self
|
||||
from typing import Dict, Self
|
||||
|
||||
from ...session import PackedChat, PackedType
|
||||
from ...tl import abcs, types
|
||||
from ...tl import abcs
|
||||
from .chat import Chat
|
||||
from .meta import NoPublicConstructor
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
from typing import Dict, List, Optional, Self
|
||||
from typing import Dict, Self
|
||||
|
||||
from ...session import PackedChat, PackedType
|
||||
from ...tl import abcs, types
|
||||
from ...tl import types
|
||||
from .chat import Chat
|
||||
from .meta import NoPublicConstructor
|
||||
|
||||
|
@@ -1,10 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import mimetypes
|
||||
import os
|
||||
from inspect import isawaitable
|
||||
from io import BufferedReader, BufferedWriter
|
||||
from mimetypes import guess_type
|
||||
from io import BufferedWriter
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Coroutine, List, Optional, Protocol, Self, Union
|
||||
|
||||
|
@@ -2,11 +2,11 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
|
||||
from ...tl import abcs, functions, types
|
||||
from ..utils import generate_random_id
|
||||
from ...tl import abcs, types, functions
|
||||
from .chat import ChatLike
|
||||
from .meta import NoPublicConstructor
|
||||
from .message import Message
|
||||
from .meta import NoPublicConstructor
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..client import Client
|
||||
|
@@ -1,6 +1,5 @@
|
||||
from typing import Dict, List, Optional, Self, Union
|
||||
from typing import Dict, Self, Union
|
||||
|
||||
from ...session import PackedChat, PackedType
|
||||
from ...tl import abcs, types
|
||||
from .chat import Chat
|
||||
from .meta import NoPublicConstructor
|
||||
|
@@ -1,6 +1,5 @@
|
||||
from typing import Dict, List, Optional, Self, Union
|
||||
from typing import Dict
|
||||
|
||||
from ...session import PackedChat, PackedType
|
||||
from ...tl import abcs, types
|
||||
from .chat import Chat
|
||||
from .meta import NoPublicConstructor
|
||||
|
@@ -2,17 +2,7 @@ import itertools
|
||||
import sys
|
||||
import time
|
||||
from collections import defaultdict
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
DefaultDict,
|
||||
Dict,
|
||||
Iterator,
|
||||
List,
|
||||
Optional,
|
||||
Union,
|
||||
cast,
|
||||
)
|
||||
from typing import DefaultDict, Dict, List, Optional, Union
|
||||
|
||||
from ..tl import abcs, types
|
||||
from .types import Channel, Chat, Group, User
|
||||
|
@@ -56,11 +56,17 @@ def ige_decrypt(ciphertext: bytes, key: bytes, iv: bytes) -> bytes:
|
||||
try:
|
||||
import cryptg
|
||||
|
||||
ige_encrypt = lambda t, k, i: cryptg.encrypt_ige(
|
||||
bytes(t) if not isinstance(t, bytes) else t, k, i
|
||||
)
|
||||
ige_decrypt = lambda t, k, i: cryptg.decrypt_ige(
|
||||
bytes(t) if not isinstance(t, bytes) else t, k, i
|
||||
)
|
||||
def ige_encrypt(plaintext: bytes, key: bytes, iv: bytes) -> bytes: # noqa: F811
|
||||
return cryptg.encrypt_ige(
|
||||
bytes(plaintext) if not isinstance(plaintext, bytes) else plaintext, key, iv
|
||||
)
|
||||
|
||||
def ige_decrypt(ciphertext: bytes, key: bytes, iv: bytes) -> bytes: # noqa: F811
|
||||
return cryptg.decrypt_ige(
|
||||
bytes(ciphertext) if not isinstance(ciphertext, bytes) else ciphertext,
|
||||
key,
|
||||
iv,
|
||||
)
|
||||
|
||||
except ImportError:
|
||||
pass
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import base64
|
||||
from typing import Any, Dict, List, Optional, Self
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
class DataCenter:
|
||||
|
@@ -6,10 +6,11 @@ from .storage import Storage
|
||||
try:
|
||||
from .sqlite import SqliteSession
|
||||
except ImportError as e:
|
||||
import_err = e
|
||||
|
||||
class SqliteSession(Storage): # type: ignore [no-redef]
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
raise e from None
|
||||
raise import_err from None
|
||||
|
||||
|
||||
__all__ = ["MemorySession", "Storage", "SqliteSession"]
|
||||
|
@@ -1 +1 @@
|
||||
from ..core import *
|
||||
from ..core import * # noqa: F403
|
||||
|
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Classes for the various objects the library returns.
|
||||
"""
|
||||
from ._impl.client.client import Config, InlineResult
|
||||
from ._impl.client.client import Config
|
||||
from ._impl.client.types import (
|
||||
AsyncList,
|
||||
Channel,
|
||||
@@ -11,6 +11,7 @@ from ._impl.client.types import (
|
||||
File,
|
||||
Group,
|
||||
InFileLike,
|
||||
InlineResult,
|
||||
LoginToken,
|
||||
Message,
|
||||
OutFileLike,
|
||||
|
@@ -4,7 +4,6 @@ import logging
|
||||
from pytest import LogCaptureFixture, mark
|
||||
from telethon._impl.mtproto import Full
|
||||
from telethon._impl.mtsender import connect
|
||||
from telethon._impl.session import DataCenter
|
||||
from telethon._impl.tl import LAYER, abcs, functions, types
|
||||
|
||||
TELEGRAM_TEST_DC = 2, "149.154.167.40:443"
|
||||
|
Reference in New Issue
Block a user