Skip to content

Commit 531069b

Browse files
Some fixes and speed improvments (pyrogram#439)
* Use raw string for re pattern * Trim trailing whitespaces from docstrings and code * Use isinstance() instead of type() for typechecking * Remove unused imports
1 parent 5261e95 commit 531069b

File tree

18 files changed

+28
-43
lines changed

18 files changed

+28
-43
lines changed

compiler/api/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
SECTION_RE = re.compile(r"---(\w+)---")
2727
LAYER_RE = re.compile(r"//\sLAYER\s(\d+)")
2828
COMBINATOR_RE = re.compile(r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);(?: // Docs: (.+))?$", re.MULTILINE)
29-
ARGS_RE = re.compile("[^{](\w+):([\w?!.<>#]+)")
29+
ARGS_RE = re.compile(r"[^{](\w+):([\w?!.<>#]+)")
3030
FLAGS_RE = re.compile(r"flags\.(\d+)\?")
3131
FLAGS_RE_2 = re.compile(r"flags\.(\d+)\?([\w<>.]+)")
3232
FLAGS_RE_3 = re.compile(r"flags:#")

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- Install requirements.
44
- Install `pandoc` and `latexmk`.
5-
- HTML: `make html`
5+
- HTML: `make html`
66
- PDF: `make latexpdf`
77

88
TODO: Explain better

pyrogram/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ def resolve_peer(self, peer_id: Union[int, str]):
16491649
try:
16501650
return self.storage.get_peer_by_id(peer_id)
16511651
except KeyError:
1652-
if type(peer_id) is str:
1652+
if isinstance(peer_id, str):
16531653
if peer_id in ("self", "me"):
16541654
return types.InputPeerSelf()
16551655

pyrogram/client/filters/filters.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class Filters:
214214

215215
from_scheduled = create(lambda _, m: bool(m.from_scheduled), "FromScheduledFilter")
216216
"""Filter new automatically sent messages that were previously scheduled."""
217-
217+
218218
# Messages from linked channels are forwarded automatically by Telegram and have no sender (from_user is None).
219219
linked_channel = create(lambda _, m: bool(m.forward_from_chat and not m.from_user), "LinkedChannelFilter")
220220
"""Filter messages that are automatically forwarded from the linked channel to the group chat."""
@@ -277,11 +277,11 @@ def func(flt, message):
277277

278278
return False
279279

280-
commands = commands if type(commands) is list else [commands]
280+
commands = commands if isinstance(commands, list) else [commands]
281281
commands = {c if case_sensitive else c.lower() for c in commands}
282282

283283
prefixes = [] if prefixes is None else prefixes
284-
prefixes = prefixes if type(prefixes) is list else [prefixes]
284+
prefixes = prefixes if isinstance(prefixes, list) else [prefixes]
285285
prefixes = set(prefixes) if prefixes else {""}
286286

287287
return create(
@@ -345,11 +345,11 @@ class user(Filter, set):
345345
"""
346346

347347
def __init__(self, users: int or str or list = None):
348-
users = [] if users is None else users if type(users) is list else [users]
348+
users = [] if users is None else users if isinstance(users, list) else [users]
349349

350350
super().__init__(
351351
"me" if u in ["me", "self"]
352-
else u.lower().strip("@") if type(u) is str
352+
else u.lower().strip("@") if isinstance(u, str)
353353
else u for u in users
354354
)
355355

@@ -376,11 +376,11 @@ class chat(Filter, set):
376376
"""
377377

378378
def __init__(self, chats: int or str or list = None):
379-
chats = [] if chats is None else chats if type(chats) is list else [chats]
379+
chats = [] if chats is None else chats if isinstance(chats, list) else [chats]
380380

381381
super().__init__(
382382
"me" if c in ["me", "self"]
383-
else c.lower().strip("@") if type(c) is str
383+
else c.lower().strip("@") if isinstance(c, str)
384384
else c for c in chats
385385
)
386386

pyrogram/client/methods/chats/delete_user_history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from typing import Union
2020

21-
from pyrogram.api import functions, types
21+
from pyrogram.api import functions
2222
from pyrogram.client.ext import BaseClient
2323

2424

pyrogram/client/methods/chats/get_chat_members.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20-
import time
2120
from typing import Union, List
2221

2322
import pyrogram
2423
from pyrogram.api import functions, types
25-
from pyrogram.errors import FloodWait
2624
from ...ext import BaseClient
2725

2826
log = logging.getLogger(__name__)

pyrogram/client/methods/chats/get_dialogs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20-
import time
2120
from typing import List
2221

2322
import pyrogram
2423
from pyrogram.api import functions, types
25-
from pyrogram.errors import FloodWait
2624
from ...ext import BaseClient, utils
2725

2826
log = logging.getLogger(__name__)

pyrogram/client/methods/chats/set_chat_photo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def set_chat_photo(
4141
photo (``str``):
4242
New chat photo. You can pass a :obj:`Photo` file_id or a file path to upload a new photo from your local
4343
machine.
44-
44+
4545
file_ref (``str``, *optional*):
4646
A valid file reference obtained by a recently fetched media message.
4747
To be used in combination with a file id in case a file reference is needed.

pyrogram/client/methods/chats/update_chat_username.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def update_chat_username(
2929
username: Union[str, None]
3030
) -> bool:
3131
"""Update a channel or a supergroup username.
32-
32+
3333
To update your own username (for users only, not bots) you can use :meth:`~Client.update_username`.
3434
3535
Parameters:

pyrogram/client/methods/messages/get_history.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20-
import time
2120
from typing import Union, List
2221

2322
import pyrogram
2423
from pyrogram.api import functions
2524
from pyrogram.client.ext import utils
26-
from pyrogram.errors import FloodWait
2725
from ...ext import BaseClient
2826

2927
log = logging.getLogger(__name__)

0 commit comments

Comments
 (0)