Title: Improve `super()` error message and document zero-arg `super()` usage inside nested functions and generator expressions. · Issue #113212 · python/cpython · GitHub
Open Graph Title: Improve `super()` error message and document zero-arg `super()` usage inside nested functions and generator expressions. · Issue #113212 · python/cpython
X Title: Improve `super()` error message and document zero-arg `super()` usage inside nested functions and generator expressions. · Issue #113212 · python/cpython
Description: Bug report Bug description: I tried searching for something related but I could not find exactly this case with super. Maybe I missed… so posting it here. Following code works fine: class A: def foo(self): return 1 class B(A): def foo(se...
Open Graph Description: Bug report Bug description: I tried searching for something related but I could not find exactly this case with super. Maybe I missed… so posting it here. Following code works fine: class A: def fo...
X Description: Bug report Bug description: I tried searching for something related but I could not find exactly this case with super. Maybe I missed… so posting it here. Following code works fine: class A: def fo...
Opengraph URL: https://github.com/python/cpython/issues/113212
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve `super()` error message and document zero-arg `super()` usage inside nested functions and generator expressions.","articleBody":"# Bug report\r\n\r\n### Bug description:\r\nI tried searching for something related but I could not find exactly this case with `super`. Maybe I missed… so posting it here.\r\nFollowing code works fine:\r\n```python\r\nclass A:\r\n def foo(self):\r\n return 1\r\n\r\n\r\nclass B(A):\r\n def foo(self):\r\n return [super().foo() for _ in range(10)]\r\n\r\n\r\nprint(B().foo())\r\n```\r\nBut if you modify it to be like this:\r\n```python\r\nclass A:\r\n def foo(self):\r\n return 1\r\n\r\n\r\nclass B(A):\r\n def foo(self):\r\n return list(super().foo() for _ in range(10))\r\n\r\n\r\nprint(B().foo())\r\n```\r\nyou will get following error:\r\n```python\r\nTypeError: super(type, obj): obj must be an instance or subtype of type\r\n```\r\nBefore https://github.com/python/cpython/pull/101441 , `[super().foo() for _ in range(10)]` would cause the same error but it was fixed implicitly by [PEP709](https://peps.python.org/pep-0709/).\r\nYou can fix this yourself by specifying type and instance in `super()`:\r\n```python\r\nclass A:\r\n def foo(self):\r\n return 1\r\n\r\n\r\nclass B(A):\r\n def foo(self):\r\n return list(super(B, self).foo() for _ in range(10))\r\n\r\n\r\nprint(B().foo())\r\n```\r\n\r\nIf you decide that fixing this makes sense, can I work on fixing it? To me it makes sense (if you decide to leave it as it is) at least to give some kind of warning or error that in this case you should explicitly provide type and instance to `super`, because it is quite confusing why user gets this error as semantically this is valid and should work\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\nLinux, macOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-113307\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/WolframAlph","@type":"Person","name":"WolframAlph"},"datePublished":"2023-12-16T09:58:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/113212/cpython/issues/113212"}
| 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:c8e95772-7eb3-195d-c671-73f85c08d44f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 80A2:A74F2:10BD788:16464AF:69699422 |
| html-safe-nonce | e52511239257b18ab0506dcb8d834564bd7d09432347926bbd927c6e8925ffaf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEEyOkE3NEYyOjEwQkQ3ODg6MTY0NjRBRjo2OTY5OTQyMiIsInZpc2l0b3JfaWQiOiI3MTI2MDA3OTMxNjYzMzg5NzMwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e4e755e88644db51874df59efaa23ae0aad72271a2f9362ebc266b1a9f42c60e |
| hovercard-subject-tag | issue:2044690094 |
| 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/113212/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cfe71aa4842f9cd382e55c866dc9f53434d8c13a2a1e10acd89de598a76ab42b/python/cpython/issues/113212 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cfe71aa4842f9cd382e55c866dc9f53434d8c13a2a1e10acd89de598a76ab42b/python/cpython/issues/113212 |
| og:image:alt | Bug report Bug description: I tried searching for something related but I could not find exactly this case with super. Maybe I missed… so posting it here. Following code works fine: class A: def fo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | WolframAlph |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3542e147982176a7ebaa23dfb559c8af16f721c03ec560c68c56b64a0f35e751 |
| 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 | af80af7cc9e3de9c336f18b208a600950a3c187c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width