Title: NamedTuples defined via Python 3.6 variable annotations should allow methods · Issue #352 · python/typing · GitHub
Open Graph Title: NamedTuples defined via Python 3.6 variable annotations should allow methods · Issue #352 · python/typing
X Title: NamedTuples defined via Python 3.6 variable annotations should allow methods · Issue #352 · python/typing
Description: Following code should work as expected In [1]: from typing import NamedTuple In [2]: class X(NamedTuple): ...: x: int ...: def double(self): ...: return 2 * x ...: In [3]: X(1).double() At the moment it throws AttributeError as there is ...
Open Graph Description: Following code should work as expected In [1]: from typing import NamedTuple In [2]: class X(NamedTuple): ...: x: int ...: def double(self): ...: return 2 * x ...: In [3]: X(1).double() At the mome...
X Description: Following code should work as expected In [1]: from typing import NamedTuple In [2]: class X(NamedTuple): ...: x: int ...: def double(self): ...: return 2 * x ...: In [3]: X(1).double() At the mome...
Opengraph URL: https://github.com/python/typing/issues/352
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NamedTuples defined via Python 3.6 variable annotations should allow methods","articleBody":"Following code should work as expected\r\n\r\n```python\r\nIn [1]: from typing import NamedTuple\r\n\r\nIn [2]: class X(NamedTuple):\r\n ...: x: int\r\n ...: def double(self):\r\n ...: return 2 * x\r\n ...: \r\n\r\nIn [3]: X(1).double()\r\n```\r\n\r\nAt the moment it throws `AttributeError` as there is no `double` method on the constructed namedtuple.\r\n\r\nThe workaround is to define methods on subclass and set `__slots__ = ()`. But unless I'm missing something, there is no reason why methods shouldn't work as expected.","author":{"url":"https://github.com/roganov","@type":"Person","name":"roganov"},"datePublished":"2017-01-13T15:40:19Z","url":"https://github.com/python/typing/issues/352"}
| 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:3bf51062-7130-dcd8-1015-03f23f718de7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AB08:3F7946:20DC364:2CBB711:6B0023C0 |
| html-safe-nonce | 1dc448f1293e5c1d371c1b62117a55e51fe471e0199875b03d32ed05391b751f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQjA4OjNGNzk0NjoyMERDMzY0OjJDQkI3MTE6NkIwMDIzQzAiLCJ2aXNpdG9yX2lkIjoiMTYxMTM4Mjg4MTI2NTkxODkxMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ee9a91b3b6549fe0ec628b137bccc27330c146289e62acca6cd58cdefc34655d |
| hovercard-subject-tag | issue:200660461 |
| 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/typing/352/issue_layout |
| twitter:image | https://opengraph.githubassets.com/77e5ca552cd247a1782344e06512d158b5072bf4921bf199c094047251d0d2e8/python/typing/issues/352 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/77e5ca552cd247a1782344e06512d158b5072bf4921bf199c094047251d0d2e8/python/typing/issues/352 |
| og:image:alt | Following code should work as expected In [1]: from typing import NamedTuple In [2]: class X(NamedTuple): ...: x: int ...: def double(self): ...: return 2 * x ...: In [3]: X(1).double() At the mome... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | roganov |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width