Title: [FEATURE] Customization of context logic · Issue #2068 · python-telegram-bot/python-telegram-bot · GitHub
Open Graph Title: [FEATURE] Customization of context logic · Issue #2068 · python-telegram-bot/python-telegram-bot
X Title: [FEATURE] Customization of context logic · Issue #2068 · python-telegram-bot/python-telegram-bot
Description: Is your feature request related to a problem? Please describe. The CallbackContext introduced in v12 is a very central thing in the library and at some point people will wanna customize it, especially when using collect_additional_contex...
Open Graph Description: Is your feature request related to a problem? Please describe. The CallbackContext introduced in v12 is a very central thing in the library and at some point people will wanna customize it, especia...
X Description: Is your feature request related to a problem? Please describe. The CallbackContext introduced in v12 is a very central thing in the library and at some point people will wanna customize it, especia...
Opengraph URL: https://github.com/python-telegram-bot/python-telegram-bot/issues/2068
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[FEATURE] Customization of context logic","articleBody":"#### Is your feature request related to a problem? Please describe.\r\n* The `CallbackContext` introduced in v12 is a very central thing in the library and at some point people will wanna customize it, especially when using `collect_additional_context` in custom handlers. Also when we get typing (#1920, due to v13), type checkers will complain setting custom attributes.\r\n* The persistence setup, which is tightly integrated with `context`, has two shortcomings:\r\n * Currently, on startup *all* data is loaded from the persistence-backend, which might slow down the startup on huge databases and even might be unneccessary. Allowing to implement a fetch-on-demand logic would solve that\r\n * When sharing a database with an external service, currently there is no automated way to update the data while running the process. Again, more customization of the persistence setup could solve that\r\n\r\n#### Describe the solution you'd like\r\n1. Allow for `BasePersistence.get_data()` to return custom classes, defaulting to `dict()`. That way users can solve both of the above mentioned problems on their own (same for `get_conversations`). For most classes this should still be compatible with the changes introduced in #1994, but advanced users can use `set/replace_bot()` manually anyway …\r\n2. Allow to pass a custom subclass of `CallbackContext` to `Updater/Dispatcher` that will be used instead of `CallbackContext`. We should document `CC.from_*()` for that.\r\n3. Those custom classes (3 for `bot/user/chat_data`, 1 for `context`) should be passable to `Updater/Dispatcher` in a clean way. I.e. probably add a single parameter to pass it as tuple/dict/custom class or maybe add it to the `Defaults` class, although I'm not sure that's a good idea\r\n4. As we're introducing type hinting in v13 (#1920), ideally the typing is clever enough to tell the handlers that they get `(update: Update, context: CustomCallbackContext)` instead of `(update: Update, context: CallbackContext)`\r\n\r\n\r\n#### Describe alternatives you've considered\r\n\r\n#### Additional context\r\nReference for devs: @JosXa @tsnoam and I had a brief discussion about some of these ideas in dev chat on 2020-08-25.\r\n","author":{"url":"https://github.com/Bibo-Joshi","@type":"Person","name":"Bibo-Joshi"},"datePublished":"2020-08-25T18:10:48Z","url":"https://github.com/python-telegram-bot/python-telegram-bot/issues/2068"}
| 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:1dd1f11e-fa16-13ba-30e0-4cda78b30024 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E64A:25F5AB:14C367A:1A39EF3:6B026E3B |
| html-safe-nonce | d813ff2ac371d6432b05a87e80005e84729989f8f0c2a0890ba88bcc047461b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjRBOjI1RjVBQjoxNEMzNjdBOjFBMzlFRjM6NkIwMjZFM0IiLCJ2aXNpdG9yX2lkIjoiNDc0MjEzNDI4NzM1NTI0NDA5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ecf4a0d58026eb763b26d7feaf3d7a14d128a820373b52bb7451ffb3c2d18cd6 |
| hovercard-subject-tag | issue:685687958 |
| 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/2068/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7ee06236ffba0012b6e646202d48a13f843c28bb7f59d47fe93a5cb564fec1ed/python-telegram-bot/python-telegram-bot/issues/2068 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7ee06236ffba0012b6e646202d48a13f843c28bb7f59d47fe93a5cb564fec1ed/python-telegram-bot/python-telegram-bot/issues/2068 |
| og:image:alt | Is your feature request related to a problem? Please describe. The CallbackContext introduced in v12 is a very central thing in the library and at some point people will wanna customize it, especia... |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width