Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@ The following wonderful people contributed directly or indirectly to this projec
- `wjt <https://github.com/wjt>`_
- `zeroone2numeral2 <https://github.com/zeroone2numeral2>`_
- `zeshuaro <https://github.com/zeshuaro>`_
- `zpavloudis <https://github.com/zpavloudis>`_

Please add yourself here alphabetically when you submit your first pull request.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ show_error_codes = True
ignore_errors = True

# Disable strict optional for telegram objects with class methods
# We don't want to clutter the code with 'if self.bot is None: raise RuntimeError()'
# We don't want to clutter the code with 'if self.text is None: raise RuntimeError()'
[mypy-telegram._callbackquery,telegram._chat,telegram._message,telegram._user,telegram._files.*,telegram._inline.inlinequery,telegram._payment.precheckoutquery,telegram._payment.shippingquery,telegram._passport.passportdata,telegram._passport.credentials,telegram._passport.passportfile,telegram.ext.filters]
strict_optional = False

Expand Down
14 changes: 7 additions & 7 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Bot(TelegramObject):
'base_url',
'base_file_url',
'private_key',
'_bot',
'_bot_user',
'_request',
'logger',
)
Expand All @@ -169,7 +169,7 @@ def __init__(

self.base_url = base_url + self.token
self.base_file_url = base_file_url + self.token
self._bot: Optional[User] = None
self._bot_user: Optional[User] = None
self._request = request or Request()
self.private_key = None
self.logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -322,9 +322,9 @@ def _validate_token(token: str) -> str:
@property
def bot(self) -> User:
""":class:`telegram.User`: User instance for the bot as returned by :meth:`get_me`."""
if self._bot is None:
self._bot = self.get_me()
return self._bot
if self._bot_user is None:
self._bot_user = self.get_me()
return self._bot_user

@property
def id(self) -> int: # pylint: disable=invalid-name
Expand Down Expand Up @@ -392,9 +392,9 @@ def get_me(self, timeout: ODVInput[float] = DEFAULT_NONE, api_kwargs: JSONDict =
"""
result = self._post('getMe', timeout=timeout, api_kwargs=api_kwargs)

self._bot = User.de_json(result, self) # type: ignore[return-value, arg-type]
self._bot_user = User.de_json(result, self) # type: ignore[return-value, arg-type]

return self._bot # type: ignore[return-value]
return self._bot_user # type: ignore[return-value]

@_log
def send_message(
Expand Down
21 changes: 10 additions & 11 deletions telegram/_callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class CallbackQuery(TelegramObject):
"""

__slots__ = (
'bot',
'game_short_name',
'message',
'chat_instance',
Expand Down Expand Up @@ -125,7 +124,7 @@ def __init__(
self.inline_message_id = inline_message_id
self.game_short_name = game_short_name

self.bot = bot
self.set_bot(bot)

self._id_attrs = (self.id,)

Expand Down Expand Up @@ -162,7 +161,7 @@ def answer(
:obj:`bool`: On success, :obj:`True` is returned.
"""
return self.bot.answer_callback_query(
return self.get_bot().answer_callback_query(
callback_query_id=self.id,
text=text,
show_alert=show_alert,
Expand Down Expand Up @@ -200,7 +199,7 @@ def edit_message_text(
"""
if self.inline_message_id:
return self.bot.edit_message_text(
return self.get_bot().edit_message_text(
inline_message_id=self.inline_message_id,
text=text,
parse_mode=parse_mode,
Expand Down Expand Up @@ -250,7 +249,7 @@ def edit_message_caption(
"""
if self.inline_message_id:
return self.bot.edit_message_caption(
return self.get_bot().edit_message_caption(
caption=caption,
inline_message_id=self.inline_message_id,
reply_markup=reply_markup,
Expand Down Expand Up @@ -303,7 +302,7 @@ def edit_message_reply_markup(
"""
if self.inline_message_id:
return self.bot.edit_message_reply_markup(
return self.get_bot().edit_message_reply_markup(
reply_markup=reply_markup,
inline_message_id=self.inline_message_id,
timeout=timeout,
Expand Down Expand Up @@ -342,7 +341,7 @@ def edit_message_media(
"""
if self.inline_message_id:
return self.bot.edit_message_media(
return self.get_bot().edit_message_media(
inline_message_id=self.inline_message_id,
media=media,
reply_markup=reply_markup,
Expand Down Expand Up @@ -391,7 +390,7 @@ def edit_message_live_location(
"""
if self.inline_message_id:
return self.bot.edit_message_live_location(
return self.get_bot().edit_message_live_location(
inline_message_id=self.inline_message_id,
latitude=latitude,
longitude=longitude,
Expand Down Expand Up @@ -444,7 +443,7 @@ def stop_message_live_location(
"""
if self.inline_message_id:
return self.bot.stop_message_live_location(
return self.get_bot().stop_message_live_location(
inline_message_id=self.inline_message_id,
reply_markup=reply_markup,
timeout=timeout,
Expand Down Expand Up @@ -485,7 +484,7 @@ def set_game_score(
"""
if self.inline_message_id:
return self.bot.set_game_score(
return self.get_bot().set_game_score(
inline_message_id=self.inline_message_id,
user_id=user_id,
score=score,
Expand Down Expand Up @@ -528,7 +527,7 @@ def get_game_high_scores(
"""
if self.inline_message_id:
return self.bot.get_game_high_scores(
return self.get_bot().get_game_high_scores(
inline_message_id=self.inline_message_id,
user_id=user_id,
timeout=timeout,
Expand Down
Loading