Title: [FEATURE/DISCUSSION] Representations of TG objects · Issue #2491 · python-telegram-bot/python-telegram-bot · GitHub
Open Graph Title: [FEATURE/DISCUSSION] Representations of TG objects · Issue #2491 · python-telegram-bot/python-telegram-bot
X Title: [FEATURE/DISCUSSION] Representations of TG objects · Issue #2491 · python-telegram-bot/python-telegram-bot
Description: This came up in church and my comment on it is too lengthy to post a question in dev chat, so here we go. Also this is not urgent in any way … Current state Currently str(tg_objec) will give str(tg_object.to_dict()) and repr(tg_object) w...
Open Graph Description: This came up in church and my comment on it is too lengthy to post a question in dev chat, so here we go. Also this is not urgent in any way … Current state Currently str(tg_objec) will give str(tg...
X Description: This came up in church and my comment on it is too lengthy to post a question in dev chat, so here we go. Also this is not urgent in any way … Current state Currently str(tg_objec) will give str(tg...
Opengraph URL: https://github.com/python-telegram-bot/python-telegram-bot/issues/2491
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[FEATURE/DISCUSSION] Representations of TG objects","articleBody":"This came up in church and my comment on it is too lengthy to post a question in dev chat, so here we go. Also this is not urgent in any way …\r\n\r\n## Current state\r\nCurrently `str(tg_objec)` will give `str(tg_object.to_dict())` and `repr(tg_object)` will give somthing like `\u003cTGObject at …>`.\r\n\r\nThe first one can be confusing for newbies as they might thing that `tg_object` is a dictionary and they will start using subscription instead of dot-notation and so on …\r\n\r\nThe second one has\r\n\r\n- the downside that we don't know the content of the object\r\n- the upside that while debugging we can easily differentiate different objects without seeing the whole blob of data. Then again, if we need that, we can alsways call `id(tg_object)`.\r\n\r\n## Desired behavior\r\n\r\nIn view of above description, I think that it would be desirable to have a more helpful representation of TG Objects. We should keep in mind that\r\n\r\n* `__repr__` goal is to be unambiguous\r\n* `__str__` goal is to be readable\r\n* `str()` calls `__repr__`, if `__str__` is not defined\r\n\r\nI think in our case \"unambiguous\" and \"readable\" largely collide. I.e. a representation of the form `ClassName(argname=value, …)` is both unambiguous and good to read. So this is what I propose we should do in detail:\r\n\r\n## Proposal:\r\n\r\n1. Add a method `TO.pprint(linebreak: bool=False, indent: int=2)`. This will return `ClassName(argname=value, …)`. When `linebreak` is `True` it will give `f'ClassName(\\n{indent*\" \"}argname=value,\\n{indent*\" \"}…)'`, so making it something like pythons built-in `pprint` for dicts. I think this should be rather straight forward. only thing that could make trouble is attributes with list-values …\r\n2. Make `TgO.__repr__` use `TgO.pprint`. Here we could argue, if you want to skip arguments that are not in `_id_attrs`, as `_id_attrs` alone can be argumed to be unambiguous. But I think we're better of just including everything\r\n3. Depending on the decision in 2., we could drop `TgO.__str__`, which would then fallback to `TgO.__repr__`\r\n\r\n## Questions:\r\n\r\n* What do you think of this?\r\n* Would this change be big enough to consider it breaking? I wouldn't say so, but being safe also doesn't hurt …","author":{"url":"https://github.com/Bibo-Joshi","@type":"Person","name":"Bibo-Joshi"},"datePublished":"2021-04-28T07:30:01Z","url":"https://github.com/python-telegram-bot/python-telegram-bot/issues/2491"}
| 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:66ec4362-e8ec-6b7f-4a99-3d1f628c017e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E10:25F5AB:6B1F97:87DCD1:6B021E69 |
| html-safe-nonce | bb9df4f31cc5fff0d8ca77cef60b5ec12e2c23c157d893965d4d87c630b1bb14 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTEwOjI1RjVBQjo2QjFGOTc6ODdEQ0QxOjZCMDIxRTY5IiwidmlzaXRvcl9pZCI6IjE3MTEyMDQ3MDI5Nzg0NDkwMDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4b2ec02e7c0d751504a2933fdf800bf98cda7393adf55d40dd504bc632e2eb61 |
| hovercard-subject-tag | issue:869594813 |
| 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/2491/issue_layout |
| twitter:image | https://opengraph.githubassets.com/43ba8ec3f63b5b0f6937d5719b658e43c6c44e271ea0c4ab5b33007ed13d9669/python-telegram-bot/python-telegram-bot/issues/2491 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/43ba8ec3f63b5b0f6937d5719b658e43c6c44e271ea0c4ab5b33007ed13d9669/python-telegram-bot/python-telegram-bot/issues/2491 |
| og:image:alt | This came up in church and my comment on it is too lengthy to post a question in dev chat, so here we go. Also this is not urgent in any way … Current state Currently str(tg_objec) will give str(tg... |
| 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