Review errors and remove some type checks

If the type is not correct, we can let the API fail instead.
This way, if the API supports more types in the future, there
does not need to be an update. This has affected participant
permissions in groups.
This commit is contained in:
Lonami Exo 2022-02-09 10:00:20 +01:00
parent 4fae119a18
commit d1836ab899
2 changed files with 1 additions and 9 deletions

View File

@ -484,8 +484,6 @@ async def edit_admin(
entity = await self.get_input_entity(entity) entity = await self.get_input_entity(entity)
user = await self.get_input_entity(user) user = await self.get_input_entity(user)
ty = helpers._entity_type(user) ty = helpers._entity_type(user)
if ty != helpers._EntityType.USER:
raise ValueError('You must pass a user entity')
perm_names = ( perm_names = (
'change_info', 'post_messages', 'edit_messages', 'delete_messages', 'change_info', 'post_messages', 'edit_messages', 'delete_messages',
@ -549,8 +547,6 @@ async def edit_permissions(
pin_messages: bool = True) -> _tl.Updates: pin_messages: bool = True) -> _tl.Updates:
entity = await self.get_input_entity(entity) entity = await self.get_input_entity(entity)
ty = helpers._entity_type(entity) ty = helpers._entity_type(entity)
if ty != helpers._EntityType.CHANNEL:
raise ValueError('You must pass either a channel or a supergroup')
rights = _tl.ChatBannedRights( rights = _tl.ChatBannedRights(
until_date=until_date, until_date=until_date,
@ -592,8 +588,6 @@ async def kick_participant(
): ):
entity = await self.get_input_entity(entity) entity = await self.get_input_entity(entity)
user = await self.get_input_entity(user) user = await self.get_input_entity(user)
if helpers._entity_type(user) != helpers._EntityType.USER:
raise ValueError('You must pass a user entity')
ty = helpers._entity_type(entity) ty = helpers._entity_type(entity)
if ty == helpers._EntityType.CHAT: if ty == helpers._EntityType.CHAT:
@ -660,8 +654,6 @@ async def get_stats(
message: 'typing.Union[int, _tl.Message]' = None, message: 'typing.Union[int, _tl.Message]' = None,
): ):
entity = await self.get_input_entity(entity) entity = await self.get_input_entity(entity)
if helpers._entity_type(entity) != helpers._EntityType.CHANNEL:
raise TypeError('You must pass a channel entity')
message = utils.get_message_id(message) message = utils.get_message_id(message)
if message is not None: if message is not None:

View File

@ -157,7 +157,7 @@ def init(
if not api_id or not api_hash: if not api_id or not api_hash:
raise ValueError( raise ValueError(
"Your API ID or Hash cannot be empty or None. " "Your API ID or Hash cannot be empty or None. "
"Refer to telethon.rtfd.io for more information.") "Refer to docs.telethon.dev for more information.")
if local_addr is not None: if local_addr is not None:
if use_ipv6 is False and ':' in local_addr: if use_ipv6 is False and ':' in local_addr: