Title: Two issues with subclassing namedtuple-generated class and overriding __new__ · Issue #1279 · python/mypy · GitHub
Open Graph Title: Two issues with subclassing namedtuple-generated class and overriding __new__ · Issue #1279 · python/mypy
X Title: Two issues with subclassing namedtuple-generated class and overriding __new__ · Issue #1279 · python/mypy
Description: Python 3.5.1, mypy 2f89c79. Test code: from typing import NamedTuple Base = NamedTuple('Base', [('param', int)]) class Child(Base): def __new__(cls, param: int = 1) -> 'Child': return Base.__new__(cls, param) print(Child()) Python result...
Open Graph Description: Python 3.5.1, mypy 2f89c79. Test code: from typing import NamedTuple Base = NamedTuple('Base', [('param', int)]) class Child(Base): def __new__(cls, param: int = 1) -> 'Child': return Base.__new__(...
X Description: Python 3.5.1, mypy 2f89c79. Test code: from typing import NamedTuple Base = NamedTuple('Base', [('param', int)]) class Child(Base): def __new__(cls, param: int = 1) -> 'Child...
Opengraph URL: https://github.com/python/mypy/issues/1279
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Two issues with subclassing namedtuple-generated class and overriding __new__","articleBody":"Python 3.5.1, mypy 2f89c79.\n\nTest code:\n\n```\nfrom typing import NamedTuple\n\nBase = NamedTuple('Base', [('param', int)])\n\n\nclass Child(Base):\n\n def __new__(cls, param: int = 1) -> 'Child':\n return Base.__new__(cls, param)\n\n\nprint(Child())\n```\n\nPython result:\n\n```\n% python3 test2.py \nChild(param=1)\n```\n\nmypy output:\n\n```\ntest2.py: note: In member \"__new__\" of class \"Child\":\ntest2.py:9: error: Too many arguments for \"__new__\" of \"object\"\ntest2.py: note: At top level:\ntest2.py:12: error: Too few arguments for \"Child\"\n```\n\nI poked around in the code a bit and I believe I managed to narrow this down to the following difference:\n- The code above depends on the namedtuple-generated class to have `__new__` defined (CPython: https://github.com/python/cpython/blob/9967d6c1053f186f3b3d118ac336a03752efec32/Lib/collections/__init__.py#L316)\n- mypy treats namedtuple definitions as if they were overriding `__init__` instead (https://github.com/python/mypy/blob/2f89c79a5b030343879f2f3c7172f0ad2b00c4de/mypy/semanal.py#L1444)\n","author":{"url":"https://github.com/jstasiak","@type":"Person","name":"jstasiak"},"datePublished":"2016-03-07T23:07:36Z","url":"https://github.com/python/mypy/issues/1279"}
| 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:8e3ef068-7c81-6e45-0e22-39b3d1bbd564 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A7B2:39DC4B:4A5D92:688DD2:6B007474 |
| html-safe-nonce | 4a14e2e7c86d6f5388d3f3ab93780f6de825dd6189b459af2670f48ca7e17234 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0IyOjM5REM0Qjo0QTVEOTI6Njg4REQyOjZCMDA3NDc0IiwidmlzaXRvcl9pZCI6IjYxNzM1NTUyOTY5MzQzMjc0MTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 703258a3ea44787db9efc04fd24088e2082d229d95ef7b8a04f727c293be40db |
| hovercard-subject-tag | issue:139121703 |
| 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/mypy/1279/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c53e1dd02e94625a0058e1646cc3006d0edb45f749a939b9cf437facaac721ff/python/mypy/issues/1279 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c53e1dd02e94625a0058e1646cc3006d0edb45f749a939b9cf437facaac721ff/python/mypy/issues/1279 |
| og:image:alt | Python 3.5.1, mypy 2f89c79. Test code: from typing import NamedTuple Base = NamedTuple('Base', [('param', int)]) class Child(Base): def __new__(cls, param: int = 1) -> 'Child': return Base.__new__(... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jstasiak |
| hostname | github.com |
| expected-hostname | github.com |
| None | 75c2b65dd205f26961d0c29afed1a8d0bb7cca9f05780571dfd1ef93eb539d16 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | 84e563eb4b55f8fa102f325f117533cee9e3df4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width