Skip to content

Commit e077d21

Browse files
authored
Merge pull request #2381 from Badiboy/master
Fix some type hints and warnings
2 parents b0466e3 + 8dcfdc5 commit e077d21

File tree

1 file changed

+48
-26
lines changed

1 file changed

+48
-26
lines changed

telebot/types.py

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ def __init__(self, message_id, from_user, date, chat, content_type, options, jso
15251525
self.json = json_string
15261526

15271527
@property
1528-
def html_text(self) -> str:
1528+
def html_text(self) -> Optional[str]:
15291529
"""
15301530
Returns html-rendered text.
15311531
"""
@@ -1534,7 +1534,7 @@ def html_text(self) -> str:
15341534
return apply_html_entities(self.text, self.entities, getattr(self, "custom_subs", None))
15351535

15361536
@property
1537-
def html_caption(self) -> str:
1537+
def html_caption(self) -> Optional[str]:
15381538
"""
15391539
Returns html-rendered caption.
15401540
"""
@@ -1618,6 +1618,14 @@ def user_shared(self):
16181618
logger.warning('The parameter "user_shared" is deprecated, use "users_shared" instead')
16191619
return self.users_shared
16201620

1621+
@property
1622+
def any_text(self) -> Optional[str]:
1623+
return self.caption if (self.caption is not None) else self.text
1624+
1625+
@property
1626+
def any_entities(self) -> Optional[List[MessageEntity]]:
1627+
return self.caption_entities if (self.caption_entities is not None) else self.entities
1628+
16211629

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

27392748

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

42704279

4280+
# noinspection PyShadowingBuiltins
42714281
class InlineQueryResultBase(ABC, Dictionaryable, JsonSerializable):
42724282
"""
42734283
This object represents one result of an inline query. Telegram clients currently support results of the following 20 types:
@@ -5407,15 +5417,16 @@ class InlineQueryResultCachedBase(ABC, JsonSerializable):
54075417
Base class of all InlineQueryResultCached* classes.
54085418
"""
54095419
def __init__(self):
5410-
self.type: str = None
5411-
self.id: str = None
5420+
self.type: str = ""
5421+
self.id: str = ""
54125422
self.title: Optional[str] = None
54135423
self.description: Optional[str] = None
54145424
self.caption: Optional[str] = None
54155425
self.reply_markup: Optional[InlineKeyboardMarkup] = None
54165426
self.input_message_content: Optional[InputMessageContent] = None
54175427
self.parse_mode: Optional[str] = None
54185428
self.caption_entities: Optional[List[MessageEntity]] = None
5429+
# noinspection PyTypeChecker
54195430
self.payload_dic: Dict[str] = {}
54205431
self.show_caption_above_media: Optional[bool] = None
54215432

@@ -7104,6 +7115,7 @@ def to_dict(self):
71047115
return json_dict
71057116

71067117

7118+
# noinspection PyShadowingBuiltins
71077119
class Poll(JsonDeserializable):
71087120
"""
71097121
This object contains information about a poll.
@@ -7586,7 +7598,7 @@ def to_dict(self):
75867598
raise NotImplementedError
75877599

75887600

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

76127624

7613-
# noinspection PyUnusedLocal
7625+
# noinspection PyUnusedLocal,PyShadowingBuiltins
76147626
class MenuButtonWebApp(MenuButton):
76157627
"""
76167628
Represents a menu button, which launches a Web App.
@@ -7645,7 +7657,7 @@ def to_json(self):
76457657
return json.dumps(self.to_dict())
76467658

76477659

7648-
# noinspection PyUnusedLocal
7660+
# noinspection PyUnusedLocal,PyShadowingBuiltins
76497661
class MenuButtonDefault(MenuButton):
76507662
"""
76517663
Describes that no specific value for the menu button was set.
@@ -8202,7 +8214,7 @@ def to_dict(self) -> dict:
82028214
def to_json(self) -> str:
82038215
return json.dumps(self.to_dict())
82048216

8205-
def convert_input_sticker(self) -> Tuple[dict, Optional[dict]]:
8217+
def convert_input_sticker(self) -> Tuple[str, Optional[dict]]:
82068218
if service_utils.is_string(self.sticker):
82078219
return self.to_json(), None
82088220

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

83458357

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

92529265
@property
9253-
def user_id(self) -> int:
9266+
def user_id(self) -> None:
92549267
logger.warning('The parameter "user_id" is deprecated, use "user_ids" instead')
92559268
return None
92569269

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

@@ -10217,8 +10230,9 @@ def de_json(cls, json_string):
1021710230
elif obj["type"] == "failed":
1021810231
return RevenueWithdrawalStateFailed.de_json(obj)
1021910232
return None
10220-
1022110233

10234+
10235+
# noinspection PyShadowingBuiltins
1022210236
class RevenueWithdrawalStatePending(RevenueWithdrawalState):
1022310237
"""
1022410238
The withdrawal is in progress.
@@ -10232,7 +10246,6 @@ class RevenueWithdrawalStatePending(RevenueWithdrawalState):
1023210246
:rtype: :class:`RevenueWithdrawalStatePending`
1023310247
"""
1023410248

10235-
# noinspection PyPackageRequirements
1023610249
def __init__(self, type, **kwargs):
1023710250
self.type: str = type
1023810251

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

1024510258

10259+
# noinspection PyShadowingBuiltins
1024610260
class RevenueWithdrawalStateSucceeded(RevenueWithdrawalState):
1024710261
"""
1024810262
The withdrawal succeeded.
@@ -10262,7 +10276,6 @@ class RevenueWithdrawalStateSucceeded(RevenueWithdrawalState):
1026210276
:rtype: :class:`RevenueWithdrawalStateSucceeded`
1026310277
"""
1026410278

10265-
# noinspection PyPackageRequirements
1026610279
def __init__(self, type, date, url, **kwargs):
1026710280
self.type: str = type
1026810281
self.date: int = date
@@ -10273,9 +10286,9 @@ def de_json(cls, json_string):
1027310286
if json_string is None: return None
1027410287
obj = cls.check_json(json_string)
1027510288
return cls(**obj)
10276-
1027710289

10278-
10290+
10291+
# noinspection PyShadowingBuiltins
1027910292
class RevenueWithdrawalStateFailed(RevenueWithdrawalState):
1028010293
"""
1028110294
The withdrawal failed and the transaction was refunded.
@@ -10289,7 +10302,6 @@ class RevenueWithdrawalStateFailed(RevenueWithdrawalState):
1028910302
:rtype: :class:`RevenueWithdrawalStateFailed`
1029010303
"""
1029110304

10292-
# noinspection PyPackageRequirements
1029310305
def __init__(self, type, **kwargs):
1029410306
self.type: str = type
1029510307

@@ -10329,7 +10341,9 @@ def de_json(cls, json_string):
1032910341
return TransactionPartnerTelegramAds.de_json(obj)
1033010342
elif obj["type"] == "other":
1033110343
return TransactionPartnerOther.de_json(obj)
10332-
10344+
10345+
10346+
# noinspection PyShadowingBuiltins
1033310347
class TransactionPartnerFragment(TransactionPartner):
1033410348
"""
1033510349
Describes a withdrawal transaction with Fragment.
@@ -10347,7 +10361,6 @@ class TransactionPartnerFragment(TransactionPartner):
1034710361
1034810362
"""
1034910363

10350-
# noinspection PyPackageRequirements
1035110364
def __init__(self, type, withdrawal_state=None, **kwargs):
1035210365
self.type: str = type
1035310366
self.withdrawal_state: Optional[RevenueWithdrawalState] = withdrawal_state
@@ -10359,9 +10372,9 @@ def de_json(cls, json_string):
1035910372
if 'withdrawal_state' in obj:
1036010373
obj['withdrawal_state'] = RevenueWithdrawalState.de_json(obj['withdrawal_state'])
1036110374
return cls(**obj)
10362-
1036310375

1036410376

10377+
# noinspection PyShadowingBuiltins
1036510378
class TransactionPartnerUser(TransactionPartner):
1036610379
"""
1036710380
Describes a transaction with a user.
@@ -10392,7 +10405,9 @@ def de_json(cls, json_string):
1039210405
obj = cls.check_json(json_string)
1039310406
obj['user'] = User.de_json(obj['user'])
1039410407
return cls(**obj)
10395-
10408+
10409+
10410+
# noinspection PyShadowingBuiltins
1039610411
class TransactionPartnerTelegramAds(TransactionPartner):
1039710412
"""
1039810413
Describes a transaction with Telegram Ads.
@@ -10413,8 +10428,10 @@ def __init__(self, type, **kwargs):
1041310428
def de_json(cls, json_string):
1041410429
if json_string is None: return None
1041510430
obj = cls.check_json(json_string)
10416-
10417-
10431+
return obj
10432+
10433+
10434+
# noinspection PyShadowingBuiltins
1041810435
class TransactionPartnerOther(TransactionPartner):
1041910436
"""
1042010437
Describes a transaction with an unknown source or recipient.
@@ -10436,9 +10453,9 @@ def de_json(cls, json_string):
1043610453
if json_string is None: return None
1043710454
obj = cls.check_json(json_string)
1043810455
return cls(**obj)
10439-
1044010456

1044110457

10458+
# noinspection PyShadowingBuiltins
1044210459
class StarTransaction(JsonDeserializable):
1044310460
"""
1044410461
Describes a Telegram Star transaction.
@@ -10531,7 +10548,9 @@ def de_json(cls, json_string):
1053110548
return PaidMediaPhoto.de_json(obj)
1053210549
elif obj["type"] == "video":
1053310550
return PaidMediaVideo.de_json(obj)
10534-
10551+
10552+
10553+
# noinspection PyShadowingBuiltins
1053510554
class PaidMediaPreview(PaidMedia):
1053610555
"""
1053710556
The paid media isn't available before the payment.
@@ -10565,8 +10584,9 @@ def de_json(cls, json_string):
1056510584
if json_string is None: return None
1056610585
obj = cls.check_json(json_string)
1056710586
return cls(**obj)
10568-
1056910587

10588+
10589+
# noinspection PyShadowingBuiltins
1057010590
class PaidMediaPhoto(PaidMedia):
1057110591
"""
1057210592
The paid media is a photo.
@@ -10595,8 +10615,9 @@ def de_json(cls, json_string):
1059510615

1059610616
obj['photo'] = [PhotoSize.de_json(photo) for photo in obj['photo']]
1059710617
return cls(**obj)
10598-
1059910618

10619+
10620+
# noinspection PyShadowingBuiltins
1060010621
class PaidMediaVideo(PaidMedia):
1060110622
"""
1060210623
The paid media is a video.
@@ -10653,6 +10674,7 @@ def __init__(self, star_count, paid_media, **kwargs):
1065310674
self.paid_media: List[PaidMedia] = paid_media
1065410675

1065510676

10677+
# noinspection PyShadowingBuiltins
1065610678
class InputPaidMedia(JsonSerializable):
1065710679
"""
1065810680
This object describes the paid media to be sent. Currently, it can be one of

0 commit comments

Comments
 (0)