Skip to content

Commit

Permalink
Change type1 or type2 to Union[type1, type2]
Browse files Browse the repository at this point in the history
  • Loading branch information
alissonlauffer committed Nov 14, 2020
1 parent e4405db commit 73689e0
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 18 deletions.
4 changes: 3 additions & 1 deletion pyrogram/connection/connection.py
Expand Up @@ -19,6 +19,8 @@
import asyncio
import logging

from typing import Union

from .transport import *
from ..session.internals import DataCenter

Expand Down Expand Up @@ -79,5 +81,5 @@ async def send(self, data: bytes):
except Exception:
raise OSError

async def recv(self) -> bytes or None:
async def recv(self) -> Union[bytes, None]:
return await self.protocol.recv()
4 changes: 3 additions & 1 deletion pyrogram/connection/transport/tcp/tcp_abridged.py
Expand Up @@ -18,6 +18,8 @@

import logging

from typing import Union

from .tcp import TCP

log = logging.getLogger(__name__)
Expand All @@ -41,7 +43,7 @@ async def send(self, data: bytes, *args):
+ data
)

async def recv(self, length: int = 0) -> bytes or None:
async def recv(self, length: int = 0) -> Union[bytes, None]:
length = await super().recv(1)

if length is None:
Expand Down
4 changes: 3 additions & 1 deletion pyrogram/connection/transport/tcp/tcp_abridged_o.py
Expand Up @@ -19,6 +19,8 @@
import logging
import os

from typing import Union

from pyrogram.crypto import aes
from .tcp import TCP

Expand Down Expand Up @@ -66,7 +68,7 @@ async def send(self, data: bytes, *args):
)
)

async def recv(self, length: int = 0) -> bytes or None:
async def recv(self, length: int = 0) -> Union[bytes, None]:
length = await super().recv(1)

if length is None:
Expand Down
3 changes: 2 additions & 1 deletion pyrogram/connection/transport/tcp/tcp_full.py
Expand Up @@ -17,6 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
from typing import Union
from binascii import crc32
from struct import pack, unpack

Expand All @@ -42,7 +43,7 @@ async def send(self, data: bytes, *args):

await super().send(data)

async def recv(self, length: int = 0) -> bytes or None:
async def recv(self, length: int = 0) -> Union[bytes, None]:
length = await super().recv(4)

if length is None:
Expand Down
3 changes: 2 additions & 1 deletion pyrogram/connection/transport/tcp/tcp_intermediate.py
Expand Up @@ -17,6 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import logging
from typing import Union
from struct import pack, unpack

from .tcp import TCP
Expand All @@ -35,7 +36,7 @@ async def connect(self, address: tuple):
async def send(self, data: bytes, *args):
await super().send(pack("<i", len(data)) + data)

async def recv(self, length: int = 0) -> bytes or None:
async def recv(self, length: int = 0) -> Union[bytes, None]:
length = await super().recv(4)

if length is None:
Expand Down
3 changes: 2 additions & 1 deletion pyrogram/connection/transport/tcp/tcp_intermediate_o.py
Expand Up @@ -18,6 +18,7 @@

import logging
import os
from typing import Union
from struct import pack, unpack

from pyrogram.crypto import aes
Expand Down Expand Up @@ -62,7 +63,7 @@ async def send(self, data: bytes, *args):
)
)

async def recv(self, length: int = 0) -> bytes or None:
async def recv(self, length: int = 0) -> Union[bytes, None]:
length = await super().recv(4)

if length is None:
Expand Down
4 changes: 2 additions & 2 deletions pyrogram/errors/rpc_error.py
Expand Up @@ -19,7 +19,7 @@
import re
from datetime import datetime
from importlib import import_module
from typing import Type
from typing import Type, Union

from pyrogram import raw
from pyrogram.raw.core import TLObject
Expand All @@ -32,7 +32,7 @@ class RPCError(Exception):
NAME = None
MESSAGE = "{x}"

def __init__(self, x: int or raw.types.RpcError = None, rpc_name: str = None, is_unknown: bool = False):
def __init__(self, x: Union[int, raw.types.RpcError] = None, rpc_name: str = None, is_unknown: bool = False):
super().__init__("[{} {}]: {} {}".format(
self.CODE,
self.ID or self.NAME,
Expand Down
6 changes: 3 additions & 3 deletions pyrogram/filters.py
Expand Up @@ -699,7 +699,7 @@ async def linked_channel_filter(_, __, m: Message):
# endregion


def command(commands: str or List[str], prefixes: str or List[str] = "/", case_sensitive: bool = False):
def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = "/", case_sensitive: bool = False):
"""Filter commands, i.e.: text messages starting with "/" or any other custom prefix.
Parameters:
Expand Down Expand Up @@ -824,7 +824,7 @@ class user(Filter, set):
Defaults to None (no users).
"""

def __init__(self, users: int or str or list = None):
def __init__(self, users: Union[int, str, list] = None):
users = [] if users is None else users if isinstance(users, list) else [users]

super().__init__(
Expand Down Expand Up @@ -856,7 +856,7 @@ class chat(Filter, set):
Defaults to None (no chats).
"""

def __init__(self, chats: int or str or list = None):
def __init__(self, chats: Union[int, str, list] = None):
chats = [] if chats is None else chats if isinstance(chats, list) else [chats]

super().__init__(
Expand Down
4 changes: 2 additions & 2 deletions pyrogram/types/messages_and_media/message.py
Expand Up @@ -2708,7 +2708,7 @@ async def edit_reply_markup(self, reply_markup: "types.InlineKeyboardMarkup" = N

async def forward(
self,
chat_id: int or str,
chat_id: Union[int, str],
disable_notification: bool = None,
as_copy: bool = False,
remove_caption: bool = False,
Expand Down Expand Up @@ -2907,7 +2907,7 @@ async def delete(self, revoke: bool = True):
revoke=revoke
)

async def click(self, x: int or str = 0, y: int = None, quote: bool = None, timeout: int = 10):
async def click(self, x: Union[int, str] = 0, y: int = None, quote: bool = None, timeout: int = 10):
"""Bound method *click* of :obj:`~pyrogram.types.Message`.
Use as a shortcut for clicking a button attached to the message instead of:
Expand Down
4 changes: 3 additions & 1 deletion pyrogram/types/messages_and_media/message_entity.py
Expand Up @@ -16,6 +16,8 @@
# 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 Union

import pyrogram
from pyrogram import raw
from pyrogram import types
Expand Down Expand Up @@ -84,7 +86,7 @@ def __init__(
self.user = user

@staticmethod
def _parse(client, entity, users: dict) -> "MessageEntity" or None:
def _parse(client, entity, users: dict) -> Union["MessageEntity", None]:
type = MessageEntity.ENTITIES.get(entity.ID, None)

if type is None:
Expand Down
4 changes: 2 additions & 2 deletions pyrogram/types/user_and_chats/chat.py
Expand Up @@ -229,7 +229,7 @@ def _parse_channel_chat(client, channel: raw.types.Channel) -> "Chat":
)

@staticmethod
def _parse(client, message: raw.types.Message or raw.types.MessageService, users: dict, chats: dict) -> "Chat":
def _parse(client, message: Union[raw.types.Message, raw.types.MessageService], users: dict, chats: dict) -> "Chat":
if isinstance(message.peer_id, raw.types.PeerUser):
return Chat._parse_user_chat(client, users[message.peer_id.user_id])

Expand All @@ -248,7 +248,7 @@ def _parse_dialog(client, peer, users: dict, chats: dict):
return Chat._parse_channel_chat(client, chats[peer.channel_id])

@staticmethod
async def _parse_full(client, chat_full: raw.types.messages.ChatFull or raw.types.UserFull) -> "Chat":
async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.types.UserFull]) -> "Chat":
if isinstance(chat_full, raw.types.UserFull):
parsed_chat = Chat._parse_user_chat(client, chat_full.user)
parsed_chat.bio = chat_full.about
Expand Down
4 changes: 2 additions & 2 deletions pyrogram/types/user_and_chats/user.py
Expand Up @@ -17,7 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import html
from typing import List
from typing import List, Union

import pyrogram
from pyrogram import raw
Expand Down Expand Up @@ -201,7 +201,7 @@ def mention(self):
return Link(f"tg://user?id={self.id}", self.first_name, self._client.parse_mode)

@staticmethod
def _parse(client, user: "raw.types.User") -> "User" or None:
def _parse(client, user: "raw.types.User") -> Union["User", None]:
if user is None:
return None

Expand Down

0 comments on commit 73689e0

Please sign in to comment.