Skip to content

Commit ea36181

Browse files
authored
Merge pull request #2584 from Badiboy/master
Bump version and minor fixes
2 parents 66ca9ea + dad1833 commit ea36181

9 files changed

Lines changed: 44 additions & 31 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
## Getting started
7171

72-
This API is tested with Python 3.9-3.13 and Pypy 3.
72+
This API is tested with Python 3.10-3.14 and PyPy 3.
7373
There are two ways to install the library:
7474

7575
* Installation using pip (a Python package manager):

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
copyright = f'2022-{datetime.now().year}, {author}'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '4.32.0'
25+
release = '4.33.0'
2626

2727

2828
# -- General configuration ---------------------------------------------------

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "pyTelegramBotAPI"
7-
version = "4.32.0"
7+
version = "4.33.0"
88
description = "Python Telegram bot API."
99
authors = [{name = "eternnoir", email = "eternnoir@gmail.com"}]
1010
license = {text = "GPL2"}
1111
readme = "README.md"
12-
requires-python = ">=3.9"
12+
requires-python = ">=3.10"
1313
keywords = ["telegram", "bot", "api", "tools"]
1414
classifiers = [
1515
"Development Status :: 5 - Production/Stable",

telebot/apihelper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,9 @@ def send_invoice(
19031903
:param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
19041904
:param reply_parameters: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.
19051905
:param message_effect_id: Unique identifier of the message effect to be added to the message; for private chats only
1906-
:param allow_paid_broadcast:
1906+
:param allow_paid_broadcast: Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
1907+
:param direct_messages_topic_id: Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
1908+
:param suggested_post_parameters: A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
19071909
:return:
19081910
"""
19091911
method_url = r'sendInvoice'

telebot/async_telebot.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ def __init__(self, token: str, parse_mode: Optional[str]=None, offset: Optional[
192192
self.middlewares = []
193193

194194
self._user = None # set during polling
195+
self._polling = None
196+
self.webhook_listener = None
195197

196198
if validate_token:
197199
util.validate_token(self.token)
@@ -203,7 +205,8 @@ def __init__(self, token: str, parse_mode: Optional[str]=None, offset: Optional[
203205
def user(self):
204206
return self._user
205207

206-
async def close_session(self):
208+
@staticmethod
209+
async def close_session():
207210
"""
208211
Closes existing session of aiohttp.
209212
Use this function if you stop polling/webhooks.
@@ -554,7 +557,7 @@ async def _run_middlewares_and_handlers(self, message, handlers, middlewares, up
554557
elif isinstance(middleware_result, SkipHandler):
555558
skip_handlers = True
556559

557-
if handlers and not(skip_handlers):
560+
if handlers and (not skip_handlers):
558561
try:
559562
for handler in handlers:
560563
params = []
@@ -4531,7 +4534,7 @@ async def send_document(
45314534
protect_content = self.protect_content if (protect_content is None) else protect_content
45324535

45334536

4534-
if data and not(document):
4537+
if data and (not document):
45354538
# function typo miss compatibility
45364539
logger.warning('The parameter "data" is deprecated. Use "document" instead.')
45374540
document = data
@@ -4664,7 +4667,7 @@ async def send_sticker(
46644667
protect_content = self.protect_content if (protect_content is None) else protect_content
46654668

46664669

4667-
if data and not(sticker):
4670+
if data and (not sticker):
46684671
# function typo miss compatibility
46694672
logger.warning('The parameter "data" is deprecated. Use "sticker" instead.')
46704673
sticker = data
@@ -4856,12 +4859,12 @@ async def send_video(
48564859
if reply_parameters and (reply_parameters.allow_sending_without_reply is None):
48574860
reply_parameters.allow_sending_without_reply = self.allow_sending_without_reply
48584861

4859-
if data and not(video):
4862+
if data and (not video):
48604863
# function typo miss compatibility
48614864
logger.warning('The parameter "data" is deprecated. Use "video" instead.')
48624865
video = data
48634866

4864-
if thumb and not(thumbnail):
4867+
if thumb and (not thumbnail):
48654868
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
48664869
thumbnail = thumb
48674870

@@ -5824,7 +5827,9 @@ async def send_contact(
58245827
await asyncio_helper.send_contact(
58255828
self.token, chat_id, phone_number, first_name, last_name, vcard,
58265829
disable_notification, reply_markup, timeout,
5827-
protect_content, message_thread_id, reply_parameters, business_connection_id, message_effect_id=message_effect_id, allow_paid_broadcast=allow_paid_broadcast))
5830+
protect_content, message_thread_id, reply_parameters, business_connection_id,
5831+
message_effect_id=message_effect_id, allow_paid_broadcast=allow_paid_broadcast,
5832+
direct_messages_topic_id=direct_messages_topic_id, suggested_post_parameters=suggested_post_parameters))
58285833

58295834
async def send_message_draft(
58305835
self, chat_id: int,
@@ -8214,6 +8219,9 @@ async def set_sticker_set_thumbnail(self, name: str, user_id: int, thumbnail: Un
82148219
HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.
82158220
:type thumbnail: :obj:`filelike object`
82168221
8222+
:param format: Format of the thumbnail, must be one of “static” for a .WEBP or .PNG image, “animated” for a .TGS animation, or “video” for a WEBM video
8223+
:type format: :obj:`str`
8224+
82178225
:return: On success, True is returned.
82188226
:rtype: :obj:`bool`
82198227
"""

telebot/asyncio_helper.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ async def _process_request(token, url, method='get', params=None, files=None, **
111111
logger.error(f'Unknown error: {e.__class__.__name__}')
112112
if not got_result:
113113
raise RequestTimeout("Request timeout. Request: method={0} url={1} params={2} files={3} request_timeout={4}".format(method, url, params, files, request_timeout, current_try))
114+
return None
114115

115116
def _prepare_file(obj):
116117
"""
@@ -119,6 +120,7 @@ def _prepare_file(obj):
119120
name = getattr(obj, 'name', None)
120121
if name and isinstance(name, str) and name[0] != '<' and name[-1] != '>':
121122
return os.path.basename(name)
123+
return None
122124

123125
def _prepare_data(params=None, files=None):
124126
"""
@@ -1251,6 +1253,7 @@ async def get_method_by_type(data_type):
12511253
return r'sendDocument'
12521254
if data_type == 'sticker':
12531255
return r'sendSticker'
1256+
return None
12541257

12551258

12561259
async def ban_chat_member(token, chat_id, user_id, until_date=None, revoke_messages=None):
@@ -1914,7 +1917,9 @@ async def send_invoice(
19141917
:param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
19151918
:param reply_parameters: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.
19161919
:param message_effect_id: Unique identifier of the message effect to be added to the message; for private chats only
1917-
:param allow_paid_broadcast:
1920+
:param allow_paid_broadcast: Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
1921+
:param direct_messages_topic_id: Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
1922+
:param suggested_post_parameters: A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
19181923
:return:
19191924
"""
19201925
method_url = r'sendInvoice'
@@ -2740,6 +2745,7 @@ async def convert_input_media(media):
27402745
async def convert_input_media_array(array):
27412746
media = []
27422747
files = {}
2748+
key = ""
27432749
for input_media in array:
27442750
if isinstance(input_media, types.InputMedia) or isinstance(input_media, types.InputPaidMedia):
27452751
media_dict = input_media.to_dict()
@@ -2831,5 +2837,3 @@ class RequestTimeout(Exception):
28312837
This class represents a request timeout.
28322838
"""
28332839
pass
2834-
2835-

telebot/handler_backends.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def dump_handlers(handlers, filename, file_mode="wb"):
103103
os.makedirs(dirs, exist_ok=True)
104104

105105
with open(filename + ".tmp", file_mode) as file:
106-
if (apihelper.CUSTOM_SERIALIZER is None):
106+
if apihelper.CUSTOM_SERIALIZER is None:
107107
pickle.dump(handlers, file)
108108
else:
109109
apihelper.CUSTOM_SERIALIZER.dump(handlers, file)
@@ -117,7 +117,7 @@ def dump_handlers(handlers, filename, file_mode="wb"):
117117
def return_load_handlers(filename, del_file_after_loading=True):
118118
if os.path.isfile(filename) and os.path.getsize(filename) > 0:
119119
with open(filename, "rb") as file:
120-
if (apihelper.CUSTOM_SERIALIZER is None):
120+
if apihelper.CUSTOM_SERIALIZER is None:
121121
handlers = pickle.load(file)
122122
else:
123123
handlers = apihelper.CUSTOM_SERIALIZER.load(file)
@@ -126,6 +126,7 @@ def return_load_handlers(filename, del_file_after_loading=True):
126126
os.remove(filename)
127127

128128
return handlers
129+
return None
129130

130131

131132
class RedisHandlerBackend(HandlerBackend):
@@ -255,4 +256,4 @@ def start2(message):
255256
256257
"""
257258
def __init__(self) -> None:
258-
pass
259+
pass

telebot/types.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5796,7 +5796,6 @@ def __init__(self):
57965796
self.input_message_content: Optional[InputMessageContent] = None
57975797
self.parse_mode: Optional[str] = None
57985798
self.caption_entities: Optional[List[MessageEntity]] = None
5799-
# noinspection PyTypeChecker
58005799
self.payload_dic: Dict[str] = {}
58015800
self.show_caption_above_media: Optional[bool] = None
58025801

@@ -7653,17 +7652,16 @@ def correct_option_id(self) -> Optional[int]:
76537652
return self.correct_option_ids[0]
76547653
return None
76557654

7656-
def add(self, option):
7655+
def add(self, option, persistent_id = None):
76577656
"""
7658-
Add an option to the poll.
7659-
7660-
:param option: Option to add
7661-
:type option: :class:`telebot.types.PollOption` or :obj:`str`
7657+
Deprecated
76627658
"""
7659+
logger.warning("Poll.add is deprecated and will be removed in future versions.")
7660+
76637661
if type(option) is PollOption:
76647662
self.options.append(option)
76657663
else:
7666-
self.options.append(PollOption(option))
7664+
self.options.append(PollOption(option, persistent_id))
76677665

76687666

76697667
class PollAnswer(JsonSerializable, JsonDeserializable, Dictionaryable):
@@ -10177,8 +10175,7 @@ class BusinessConnection(JsonDeserializable):
1017710175
:param date: Date the connection was established in Unix time
1017810176
:type date: :obj:`int`
1017910177

10180-
:param can_reply: Deprecated, use :attr:`rights` instead. True, if the bot can reply to messages from the business account
10181-
:type can_reply: :obj:`bool`
10178+
:param can_reply: Deprecated, use :attr:`rights` instead.
1018210179

1018310180
:param rights: Optional. Rights of the business bot
1018410181
:type rights: :class:`BusinessBotRights`
@@ -10198,7 +10195,7 @@ def de_json(cls, json_string):
1019810195
obj['rights'] = BusinessBotRights.de_json(obj.get('rights'))
1019910196
return cls(**obj)
1020010197

10201-
def __init__(self, id, user, user_chat_id, date, can_reply, is_enabled,
10198+
def __init__(self, id, user, user_chat_id, date, is_enabled,
1020210199
rights=None, **kwargs):
1020310200
self.id: str = id
1020410201
self.user: User = user
@@ -13219,6 +13216,7 @@ def to_dict(self):
1321913216
data['others_can_add_tasks'] = self.others_can_add_tasks
1322013217
if self.others_can_mark_tasks_as_done is not None:
1322113218
data['others_can_mark_tasks_as_done'] = self.others_can_mark_tasks_as_done
13219+
return data
1322213220

1322313221

1322413222
class ChecklistTasksDone(JsonDeserializable):
@@ -13905,8 +13903,9 @@ def de_json(cls, json_string):
1390513903
obj['bot'] = User.de_json(obj['bot'])
1390613904

1390713905
return cls(**obj)
13908-
1390913906

13907+
13908+
# noinspection PyShadowingBuiltins
1391013909
class PreparedKeyboardButton(JsonDeserializable):
1391113910
"""
1391213911
Describes a keyboard button to be used by a user of a Mini App.
@@ -14017,4 +14016,3 @@ def de_json(cls, json_string):
1401714016
if 'option_text_entities' in obj:
1401814017
obj['option_text_entities'] = [MessageEntity.de_json(entity) for entity in obj['option_text_entities']]
1401914018
return cls(**obj)
14020-

telebot/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Versions should comply with PEP440.
22
# This line is parsed in setup.py:
3-
__version__ = '4.32.0'
3+
__version__ = '4.33.0'

0 commit comments

Comments
 (0)