Title: `pydoc` renders `from builtins.type` note, even if it is incorrect · Issue #97959 · python/cpython · GitHub
Open Graph Title: `pydoc` renders `from builtins.type` note, even if it is incorrect · Issue #97959 · python/cpython
X Title: `pydoc` renders `from builtins.type` note, even if it is incorrect · Issue #97959 · python/cpython
Description: While working on #97958 I've noticed that there's something strange with help() and classmethods. Take a look at this example: import pydoc class My: @classmethod def __init_subclass__(cls, *args, **kwargs): pass @classmethod def custom(...
Open Graph Description: While working on #97958 I've noticed that there's something strange with help() and classmethods. Take a look at this example: import pydoc class My: @classmethod def __init_subclass__(cls, *args, ...
X Description: While working on #97958 I've noticed that there's something strange with help() and classmethods. Take a look at this example: import pydoc class My: @classmethod def __init_subclass__(cls,...
Opengraph URL: https://github.com/python/cpython/issues/97959
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`pydoc` renders `from builtins.type` note, even if it is incorrect","articleBody":"While working on https://github.com/python/cpython/pull/97958 I've noticed that there's something strange with `help()` and `classmethod`s.\r\n\r\nTake a look at this example:\r\n\r\n```python\r\nimport pydoc\r\n\r\nclass My:\r\n @classmethod\r\n def __init_subclass__(cls, *args, **kwargs):\r\n pass\r\n\r\n @classmethod\r\n def custom(cls):\r\n pass\r\n\r\nprint(pydoc.plain(pydoc.render_doc(My)))\r\n```\r\n\r\nIt prints:\r\n\r\n```\r\nPython Library Documentation: class My in module __main__\r\n\r\nclass My(builtins.object)\r\n | Class methods defined here:\r\n |\r\n | __init_subclass__(*args, **kwargs) from builtins.type\r\n | This method is called when a class is subclassed.\r\n |\r\n | The default implementation does nothing. It may be\r\n | overridden to extend subclasses.\r\n |\r\n | custom() from builtins.type\r\n |\r\n | ----------------------------------------------------------------------\r\n | Data descriptors defined here:\r\n |\r\n | __dict__\r\n | dictionary for instance variables (if defined)\r\n |\r\n | __weakref__\r\n | list of weak references to the object (if defined)\r\n```\r\n\r\nTake a look at these two entries:\r\n1. `__init_subclass__(*args, **kwargs) from builtins.type`\r\n2. `custom() from builtins.type`\r\n\r\nWhile `type` has `__init_subclass__`, there's no `type.custom`. But, `help` says that there is!\r\n\r\n```python\r\n\u003e\u003e\u003e type.__init_subclass__\r\n\u003cbuilt-in method __init_subclass__ of type object at 0x10a50c360\u003e\r\n\u003e\u003e\u003e type.custom\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\nAttributeError: type object 'type' has no attribute 'custom'\r\n```\r\n\r\nI think that it is incorrect and can lead to confusion.\r\nInstead it should be:\r\n\r\n```\r\n | __init_subclass__(*args, **kwargs) from builtins.type\r\n | This method is called when a class is subclassed.\r\n |\r\n | The default implementation does nothing. It may be\r\n | overridden to extend subclasses.\r\n |\r\n | custom()\r\n```\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-98120\n* gh-113941\n* gh-115296\n* gh-115302\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2022-10-06T12:08:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/97959/cpython/issues/97959"}
| 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:15c2e50c-45df-2461-5d7e-40a0d104115d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EBB8:29C2E1:32E5C:4102A:6A532488 |
| html-safe-nonce | 2fc36de815144136c7df996f9b2d11bbf7176049f2d01847bc14c083a7d3cc36 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkI4OjI5QzJFMTozMkU1Qzo0MTAyQTo2QTUzMjQ4OCIsInZpc2l0b3JfaWQiOiIzMjAyODAxODQyMjAwNDU0MjgwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2eaf5b442e05462ea35f330de9e4fa93cc975bacb0c747ce00d4d477dea5374e |
| hovercard-subject-tag | issue:1399483876 |
| 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/97959/issue_layout |
| twitter:image | https://opengraph.githubassets.com/745d2ad735bb6ae93071091d1a893d83f65954ade1337182dfd31b47e2e459ea/python/cpython/issues/97959 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/745d2ad735bb6ae93071091d1a893d83f65954ade1337182dfd31b47e2e459ea/python/cpython/issues/97959 |
| og:image:alt | While working on #97958 I've noticed that there's something strange with help() and classmethods. Take a look at this example: import pydoc class My: @classmethod def __init_subclass__(cls, *args, ... |
| 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 | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width