Skip to content

Commit

Permalink
(fix): mistake in is_iterable condition
Browse files Browse the repository at this point in the history
Follow-Up ddad27a
  • Loading branch information
SpEcHiDe authored Feb 19, 2025
1 parent bdda1f2 commit 5a6fda8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
8 changes: 3 additions & 5 deletions pyrogram/methods/chat_topics/get_forum_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
from collections.abc import Iterable
from typing import Union
from typing import Union, Iterable

import pyrogram
from pyrogram import raw
from pyrogram import types
from pyrogram import raw, types, utils

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -61,7 +59,7 @@ async def get_forum_topic(
ValueError: In case of invalid arguments.
"""

is_iterable = isinstance(message_thread_ids, Iterable)
is_iterable = utils.is_list_like(message_thread_ids)
ids = list(message_thread_ids) if is_iterable else [message_thread_ids]

r = await self.invoke(
Expand Down
8 changes: 3 additions & 5 deletions pyrogram/methods/messages/forward_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
# 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 collections.abc import Iterable
from datetime import datetime
from typing import Union
from typing import Union, Iterable

import pyrogram
from pyrogram import raw, utils
from pyrogram import types
from pyrogram import raw, types, utils


class ForwardMessages:
Expand Down Expand Up @@ -105,7 +103,7 @@ async def forward_messages(
await app.forward_messages(to_chat, from_chat, [1, 2, 3])
"""

is_iterable = isinstance(message_ids, Iterable)
is_iterable = utils.is_list_like(message_ids)
message_ids = list(message_ids) if is_iterable else [message_ids]

r = await self.invoke(
Expand Down
7 changes: 3 additions & 4 deletions pyrogram/methods/messages/get_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
from collections.abc import Iterable
from typing import Optional, Union
from typing import Iterable, Optional, Union

import pyrogram
from pyrogram import raw, types, utils
Expand Down Expand Up @@ -93,7 +92,7 @@ async def get_messages(
"""

if message_ids:
is_iterable = isinstance(message_ids, Iterable)
is_iterable = utils.is_list_like(message_ids)
ids = list(message_ids) if is_iterable else [message_ids]

if replies < 0:
Expand Down Expand Up @@ -331,7 +330,7 @@ async def get_replied_message(
"""

peer = await self.resolve_peer(chat_id)
is_iterable = isinstance(message_ids, Iterable)
is_iterable = utils.is_list_like(message_ids)
ids = list(message_ids) if is_iterable else [message_ids]
ids = [raw.types.InputMessageReplyTo(id=i) for i in ids]
if isinstance(peer, raw.types.InputPeerChannel):
Expand Down
7 changes: 3 additions & 4 deletions pyrogram/methods/stories/get_stories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
# 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 collections.abc import Iterable
from typing import Union
from typing import Union, Iterable

import pyrogram
from pyrogram import raw, types
from pyrogram import raw, types, utils


class GetStories:
Expand Down Expand Up @@ -58,7 +57,7 @@ async def get_stories(
print(story)
"""

is_iterable = isinstance(story_ids, Iterable)
is_iterable = utils.is_list_like(story_ids)
ids = list(story_ids) if is_iterable else [story_ids]

peer = await self.resolve_peer(story_sender_chat_id)
Expand Down
8 changes: 3 additions & 5 deletions pyrogram/methods/users/get_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import asyncio
from collections.abc import Iterable
from typing import Union
from typing import Union, Iterable

import pyrogram
from pyrogram import raw
from pyrogram import types
from pyrogram import raw, types, utils


class GetUsers:
Expand Down Expand Up @@ -54,7 +52,7 @@ async def get_users(
await app.get_users([user_id1, user_id2, user_id3])
"""

is_iterable = isinstance(user_ids, Iterable)
is_iterable = utils.is_list_like(user_ids)
user_ids = list(user_ids) if is_iterable else [user_ids]
user_ids = await asyncio.gather(*[self.resolve_peer(i) for i in user_ids])

Expand Down
9 changes: 9 additions & 0 deletions pyrogram/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,12 @@ def from_inline_bytes(data: bytes, file_name: str = None) -> BytesIO:
b.write(data)
b.name = file_name if file_name else f"photo_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.jpg"
return b


def is_list_like(obj):
"""
Returns `True` if the given object looks like a list.
Ported from https://github.com/LonamiWebs/Telethon/blob/1cb5ff1dd54ecfad41711fc5a4ecf36d2ad8eaf6/telethon/utils.py#L902
"""
return isinstance(obj, (list, tuple, set, dict, range))

0 comments on commit 5a6fda8

Please sign in to comment.