Title: `help()` on types has strange `(if defined)` notice for attributes that are defined · Issue #112266 · python/cpython · GitHub
Open Graph Title: `help()` on types has strange `(if defined)` notice for attributes that are defined · Issue #112266 · python/cpython
X Title: `help()` on types has strange `(if defined)` notice for attributes that are defined · Issue #112266 · python/cpython
Description: Feature or enhancement Let's say we have a regular class and we call help() on it: >>> class A: ... ... >>> help(A) Help on class A in module __main__: class A(builtins.object) | Data descriptors defined here: | | __dict__ | dictionary f...
Open Graph Description: Feature or enhancement Let's say we have a regular class and we call help() on it: >>> class A: ... ... >>> help(A) Help on class A in module __main__: class A(builtins.object) | Data descriptors d...
X Description: Feature or enhancement Let's say we have a regular class and we call help() on it: >>> class A: ... ... >>> help(A) Help on class A in module __main__: class A(builtins.object...
Opengraph URL: https://github.com/python/cpython/issues/112266
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`help()` on types has strange `(if defined)` notice for attributes that are defined","articleBody":"# Feature or enhancement\n\nLet's say we have a regular class and we call `help()` on it:\n\n```python\n\u003e\u003e\u003e class A: ...\n... \n\u003e\u003e\u003e help(A)\nHelp on class A in module __main__:\n\nclass A(builtins.object)\n | Data descriptors defined here:\n |\n | __dict__\n | dictionary for instance variables (if defined)\n |\n | __weakref__\n | list of weak references to the object (if defined)\n```\n\nThis leaves a strange impression: what does it mean for `__dict__`? \n\n\u003e dictionary for instance variables (if defined)\n\nIt is defined. \n\nThe same for regular `__doc__`:\n\n```python\n\u003e\u003e\u003e A.__dict__['__dict__'].__doc__\n'dictionary for instance variables (if defined)'\n```\n\nLet's see what happens when `__dict__` and `__weakref__` are not defined:\n\n```python\n\u003e\u003e\u003e class B:\n... __slots__ = ()\n... \n\u003e\u003e\u003e help(B)\nHelp on class B in module __main__:\n\nclass B(builtins.object)\n\n```\n\nAnd:\n\n```python\n\u003e\u003e\u003e B.__dict__['__dict__']\nTraceback (most recent call last):\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n B.__dict__['__dict__']\n ~~~~~~~~~~^^^^^^^^^^^^\nKeyError: '__dict__'\n```\n\nThe historical reason behind it is: https://github.com/python/cpython/commit/373c7412f297c375d84c5984f753557b441dd6f4#diff-1decebeef15f4e0b0ce106c665751ec55068d4d1d1825847925ad4f528b5b872R1356-R1377\n\nWhat do others think: should we remove `(if defined)` part? \nIf so, I have a PR ready.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-112268\n* gh-112270\n* gh-112276\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2023-11-19T12:20:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/112266/cpython/issues/112266"}
| 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:d99f5143-58a9-ad57-f36b-4172584dce75 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CF66:1C07BE:E7A1B6:1423391:696A3CA8 |
| html-safe-nonce | aea22b37f63542c13cd6bdae6ad64f9c68325e06f9b60582e0800b9132286c04 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjY2OjFDMDdCRTpFN0ExQjY6MTQyMzM5MTo2OTZBM0NBOCIsInZpc2l0b3JfaWQiOiIzMTQwMjcxMTA4MzgwMDQ4NTUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c3d8a1d4135aec3e93d225210b271f69c27b6fba1ff9c701c27f90b840a57048 |
| hovercard-subject-tag | issue:2000827543 |
| 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/cpython/112266/issue_layout |
| twitter:image | https://opengraph.githubassets.com/01373c5d5a99f28fed951e8426ed7946100bb07730327c35396fc142c96260b7/python/cpython/issues/112266 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/01373c5d5a99f28fed951e8426ed7946100bb07730327c35396fc142c96260b7/python/cpython/issues/112266 |
| og:image:alt | Feature or enhancement Let's say we have a regular class and we call help() on it: >>> class A: ... ... >>> help(A) Help on class A in module __main__: class A(builtins.object) | Data descriptors d... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sobolevn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 321736bfdb3f591415ae895a0459bec204b26a76caf47ba5c980634cfacc4538 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | 13581a31d51edf4a3aca179e10890a4d4f9b6d76 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width