Title: Refactor handling of shortcut-bots · Issue #2505 · python-telegram-bot/python-telegram-bot · GitHub
Open Graph Title: Refactor handling of shortcut-bots · Issue #2505 · python-telegram-bot/python-telegram-bot
X Title: Refactor handling of shortcut-bots · Issue #2505 · python-telegram-bot/python-telegram-bot
Description: A bunch of TG-Objects have bot attribute that is used for the shortcuts, e.g. self.bot.send_message(…), which is dangerous in the rare edge cases where users manually instantiate those objects and forget to pass the bot. This will then l...
Open Graph Description: A bunch of TG-Objects have bot attribute that is used for the shortcuts, e.g. self.bot.send_message(…), which is dangerous in the rare edge cases where users manually instantiate those objects and ...
X Description: A bunch of TG-Objects have bot attribute that is used for the shortcuts, e.g. self.bot.send_message(…), which is dangerous in the rare edge cases where users manually instantiate those objects and ...
Opengraph URL: https://github.com/python-telegram-bot/python-telegram-bot/issues/2505
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Refactor handling of shortcut-bots","articleBody":"A bunch of TG-Objects have `bot` attribute that is used for the shortcuts, e.g. `self.bot.send_message(…)`, which is dangerous in the rare edge cases where users manually instantiate those objects and forget to pass the `bot`. This will then lead to somewhat unprecise error messages `NoneType has no attribute 'send_message'`.\r\nMoreover, `Message.bot` is undocumented, but not private, so people relying on auto-complete may be using it without knowing that it's not really intended for external use.\r\n\r\n## Proposal:\r\n\r\nDo something like\r\n\r\n```python\r\nTGObject:\r\n self._bot: Optional[Bot] = None\r\n\r\n def get_bot(self) -> Bot:\r\n if self._bot is None:\r\n raise RuntimeError('This object has no bot and shortcuts cant be used')\r\n return self._bot\r\n\r\n def set_bot(self, bot: Bot) -> None:\r\n self._bot = bot\r\n```\r\n\r\nThis way we have helpful error messages without having to check `if self.bot is None` in every shortcut.\r\n\r\nAn alternate solution would be to make `TGObject.bot` a property that raises the error if `_bot is None`. But explicitly calling a method makes it more clear that something *could* go wrong, IMO.\r\n\r\n---\r\nNote: We briefly discussed this in dev-chat on 04-05-2021, see https://t.me/c/1494805131/15168","author":{"url":"https://github.com/Bibo-Joshi","@type":"Person","name":"Bibo-Joshi"},"datePublished":"2021-05-05T06:32:04Z","url":"https://github.com/python-telegram-bot/python-telegram-bot/issues/2505"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7c60b415-c48e-a311-d528-3006c41533f9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ED50:153FFA:D27FA4:1146199:6B02755F |
| html-safe-nonce | 27833498eaae0f5c67e69fa550987d5457f4da4f96e98ad184c93170c76402eb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDUwOjE1M0ZGQTpEMjdGQTQ6MTE0NjE5OTo2QjAyNzU1RiIsInZpc2l0b3JfaWQiOiI2ODQ2NjA5OTU4MjE0MjAyNzIwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | fc9db2dfa5f1268227f77c8ac2f2a50800869dfbdf0d87f4a469e0a5e47baa9a |
| hovercard-subject-tag | issue:876108931 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-telegram-bot/python-telegram-bot/2505/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4a5eeb461c681cf6e5a5087bb21b993dc8c9a365d0fea10462e335585c47e5f2/python-telegram-bot/python-telegram-bot/issues/2505 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4a5eeb461c681cf6e5a5087bb21b993dc8c9a365d0fea10462e335585c47e5f2/python-telegram-bot/python-telegram-bot/issues/2505 |
| og:image:alt | A bunch of TG-Objects have bot attribute that is used for the shortcuts, e.g. self.bot.send_message(…), which is dangerous in the rare edge cases where users manually instantiate those objects and ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Bibo-Joshi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-telegram-bot/python-telegram-bot git https://github.com/python-telegram-bot/python-telegram-bot.git |
| octolytics-dimension-user_id | 16178365 |
| octolytics-dimension-user_login | python-telegram-bot |
| octolytics-dimension-repository_id | 38696925 |
| octolytics-dimension-repository_nwo | python-telegram-bot/python-telegram-bot |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 38696925 |
| octolytics-dimension-repository_network_root_nwo | python-telegram-bot/python-telegram-bot |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width