Skip to content

Commit

Permalink
Merge pull request #2381 from Badiboy/master
Browse files Browse the repository at this point in the history
Fix some type hints and warnings
  • Loading branch information
Badiboy authored Aug 17, 2024
2 parents b0466e3 + 8dcfdc5 commit e077d21
Showing 1 changed file with 48 additions and 26 deletions.
74 changes: 48 additions & 26 deletions telebot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ def __init__(self, message_id, from_user, date, chat, content_type, options, jso
self.json = json_string

@property
def html_text(self) -> str:
def html_text(self) -> Optional[str]:
"""
Returns html-rendered text.
"""
Expand All @@ -1534,7 +1534,7 @@ def html_text(self) -> str:
return apply_html_entities(self.text, self.entities, getattr(self, "custom_subs", None))

@property
def html_caption(self) -> str:
def html_caption(self) -> Optional[str]:
"""
Returns html-rendered caption.
"""
Expand Down Expand Up @@ -1618,6 +1618,14 @@ def user_shared(self):
logger.warning('The parameter "user_shared" is deprecated, use "users_shared" instead')
return self.users_shared

@property
def any_text(self) -> Optional[str]:
return self.caption if (self.caption is not None) else self.text

@property
def any_entities(self) -> Optional[List[MessageEntity]]:
return self.caption_entities if (self.caption_entities is not None) else self.entities


# noinspection PyShadowingBuiltins
class MessageEntity(Dictionaryable, JsonSerializable, JsonDeserializable):
Expand Down Expand Up @@ -2734,6 +2742,7 @@ def __init__(self, text: str, request_contact: Optional[bool]=None,
if request_user is not None:
logger.warning('The parameter "request_user" is deprecated, use "request_users" instead')
if self.request_users is None:
# noinspection PyTypeChecker
self.request_users = request_user


Expand Down Expand Up @@ -4268,6 +4277,7 @@ def __init__(self, result_id, from_user, query, location=None, inline_message_id
self.query: str = query


# noinspection PyShadowingBuiltins
class InlineQueryResultBase(ABC, Dictionaryable, JsonSerializable):
"""
This object represents one result of an inline query. Telegram clients currently support results of the following 20 types:
Expand Down Expand Up @@ -5407,15 +5417,16 @@ class InlineQueryResultCachedBase(ABC, JsonSerializable):
Base class of all InlineQueryResultCached* classes.
"""
def __init__(self):
self.type: str = None
self.id: str = None
self.type: str = ""
self.id: str = ""
self.title: Optional[str] = None
self.description: Optional[str] = None
self.caption: Optional[str] = None
self.reply_markup: Optional[InlineKeyboardMarkup] = None
self.input_message_content: Optional[InputMessageContent] = None
self.parse_mode: Optional[str] = None
self.caption_entities: Optional[List[MessageEntity]] = None
# noinspection PyTypeChecker
self.payload_dic: Dict[str] = {}
self.show_caption_above_media: Optional[bool] = None

Expand Down Expand Up @@ -7104,6 +7115,7 @@ def to_dict(self):
return json_dict


# noinspection PyShadowingBuiltins
class Poll(JsonDeserializable):
"""
This object contains information about a poll.
Expand Down Expand Up @@ -7586,7 +7598,7 @@ def to_dict(self):
raise NotImplementedError


# noinspection PyUnusedLocal
# noinspection PyUnusedLocal,PyShadowingBuiltins
class MenuButtonCommands(MenuButton):
"""
Represents a menu button, which opens the bot's list of commands.
Expand All @@ -7610,7 +7622,7 @@ def to_json(self):
return json.dumps(self.to_dict())


# noinspection PyUnusedLocal
# noinspection PyUnusedLocal,PyShadowingBuiltins
class MenuButtonWebApp(MenuButton):
"""
Represents a menu button, which launches a Web App.
Expand Down Expand Up @@ -7645,7 +7657,7 @@ def to_json(self):
return json.dumps(self.to_dict())


# noinspection PyUnusedLocal
# noinspection PyUnusedLocal,PyShadowingBuiltins
class MenuButtonDefault(MenuButton):
"""
Describes that no specific value for the menu button was set.
Expand Down Expand Up @@ -8202,7 +8214,7 @@ def to_dict(self) -> dict:
def to_json(self) -> str:
return json.dumps(self.to_dict())

def convert_input_sticker(self) -> Tuple[dict, Optional[dict]]:
def convert_input_sticker(self) -> Tuple[str, Optional[dict]]:
if service_utils.is_string(self.sticker):
return self.to_json(), None

Expand Down Expand Up @@ -8343,6 +8355,7 @@ def to_json(self) -> str:
return json.dumps(self.to_dict())


# noinspection PyShadowingBuiltins
class Story(JsonDeserializable):
"""
This object represents a story.
Expand Down Expand Up @@ -9250,12 +9263,12 @@ def __init__(self, request_id: int, users: List[SharedUser], **kwargs):
self.users: List[SharedUser] = users

@property
def user_id(self) -> int:
def user_id(self) -> None:
logger.warning('The parameter "user_id" is deprecated, use "user_ids" instead')
return None

@property
def user_ids(self) -> List[int]:
def user_ids(self) -> List[SharedUser]:
logger.warning('The parameter "user_ids" is deprecated, use "users" instead')
return self.users

Expand Down Expand Up @@ -10217,8 +10230,9 @@ def de_json(cls, json_string):
elif obj["type"] == "failed":
return RevenueWithdrawalStateFailed.de_json(obj)
return None



# noinspection PyShadowingBuiltins
class RevenueWithdrawalStatePending(RevenueWithdrawalState):
"""
The withdrawal is in progress.
Expand All @@ -10232,7 +10246,6 @@ class RevenueWithdrawalStatePending(RevenueWithdrawalState):
:rtype: :class:`RevenueWithdrawalStatePending`
"""

# noinspection PyPackageRequirements
def __init__(self, type, **kwargs):
self.type: str = type

Expand All @@ -10243,6 +10256,7 @@ def de_json(cls, json_string):
return cls(**obj)


# noinspection PyShadowingBuiltins
class RevenueWithdrawalStateSucceeded(RevenueWithdrawalState):
"""
The withdrawal succeeded.
Expand All @@ -10262,7 +10276,6 @@ class RevenueWithdrawalStateSucceeded(RevenueWithdrawalState):
:rtype: :class:`RevenueWithdrawalStateSucceeded`
"""

# noinspection PyPackageRequirements
def __init__(self, type, date, url, **kwargs):
self.type: str = type
self.date: int = date
Expand All @@ -10273,9 +10286,9 @@ def de_json(cls, json_string):
if json_string is None: return None
obj = cls.check_json(json_string)
return cls(**obj)




# noinspection PyShadowingBuiltins
class RevenueWithdrawalStateFailed(RevenueWithdrawalState):
"""
The withdrawal failed and the transaction was refunded.
Expand All @@ -10289,7 +10302,6 @@ class RevenueWithdrawalStateFailed(RevenueWithdrawalState):
:rtype: :class:`RevenueWithdrawalStateFailed`
"""

# noinspection PyPackageRequirements
def __init__(self, type, **kwargs):
self.type: str = type

Expand Down Expand Up @@ -10329,7 +10341,9 @@ def de_json(cls, json_string):
return TransactionPartnerTelegramAds.de_json(obj)
elif obj["type"] == "other":
return TransactionPartnerOther.de_json(obj)



# noinspection PyShadowingBuiltins
class TransactionPartnerFragment(TransactionPartner):
"""
Describes a withdrawal transaction with Fragment.
Expand All @@ -10347,7 +10361,6 @@ class TransactionPartnerFragment(TransactionPartner):
"""

# noinspection PyPackageRequirements
def __init__(self, type, withdrawal_state=None, **kwargs):
self.type: str = type
self.withdrawal_state: Optional[RevenueWithdrawalState] = withdrawal_state
Expand All @@ -10359,9 +10372,9 @@ def de_json(cls, json_string):
if 'withdrawal_state' in obj:
obj['withdrawal_state'] = RevenueWithdrawalState.de_json(obj['withdrawal_state'])
return cls(**obj)



# noinspection PyShadowingBuiltins
class TransactionPartnerUser(TransactionPartner):
"""
Describes a transaction with a user.
Expand Down Expand Up @@ -10392,7 +10405,9 @@ def de_json(cls, json_string):
obj = cls.check_json(json_string)
obj['user'] = User.de_json(obj['user'])
return cls(**obj)



# noinspection PyShadowingBuiltins
class TransactionPartnerTelegramAds(TransactionPartner):
"""
Describes a transaction with Telegram Ads.
Expand All @@ -10413,8 +10428,10 @@ def __init__(self, type, **kwargs):
def de_json(cls, json_string):
if json_string is None: return None
obj = cls.check_json(json_string)


return obj


# noinspection PyShadowingBuiltins
class TransactionPartnerOther(TransactionPartner):
"""
Describes a transaction with an unknown source or recipient.
Expand All @@ -10436,9 +10453,9 @@ def de_json(cls, json_string):
if json_string is None: return None
obj = cls.check_json(json_string)
return cls(**obj)



# noinspection PyShadowingBuiltins
class StarTransaction(JsonDeserializable):
"""
Describes a Telegram Star transaction.
Expand Down Expand Up @@ -10531,7 +10548,9 @@ def de_json(cls, json_string):
return PaidMediaPhoto.de_json(obj)
elif obj["type"] == "video":
return PaidMediaVideo.de_json(obj)



# noinspection PyShadowingBuiltins
class PaidMediaPreview(PaidMedia):
"""
The paid media isn't available before the payment.
Expand Down Expand Up @@ -10565,8 +10584,9 @@ def de_json(cls, json_string):
if json_string is None: return None
obj = cls.check_json(json_string)
return cls(**obj)



# noinspection PyShadowingBuiltins
class PaidMediaPhoto(PaidMedia):
"""
The paid media is a photo.
Expand Down Expand Up @@ -10595,8 +10615,9 @@ def de_json(cls, json_string):

obj['photo'] = [PhotoSize.de_json(photo) for photo in obj['photo']]
return cls(**obj)



# noinspection PyShadowingBuiltins
class PaidMediaVideo(PaidMedia):
"""
The paid media is a video.
Expand Down Expand Up @@ -10653,6 +10674,7 @@ def __init__(self, star_count, paid_media, **kwargs):
self.paid_media: List[PaidMedia] = paid_media


# noinspection PyShadowingBuiltins
class InputPaidMedia(JsonSerializable):
"""
This object describes the paid media to be sent. Currently, it can be one of
Expand Down

0 comments on commit e077d21

Please sign in to comment.