Title: Implement Const type to indicate non-rebindable variables/attributes · Issue #1214 · python/mypy · GitHub
Open Graph Title: Implement Const type to indicate non-rebindable variables/attributes · Issue #1214 · python/mypy
X Title: Implement Const type to indicate non-rebindable variables/attributes · Issue #1214 · python/mypy
Description: As a Python developer, I would like a Const type so that I can indicate that a variable or attribute may not be rebound to another value. This would be especially useful for module and class constants, but could also be helpful for insta...
Open Graph Description: As a Python developer, I would like a Const type so that I can indicate that a variable or attribute may not be rebound to another value. This would be especially useful for module and class consta...
X Description: As a Python developer, I would like a Const type so that I can indicate that a variable or attribute may not be rebound to another value. This would be especially useful for module and class consta...
Opengraph URL: https://github.com/python/mypy/issues/1214
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Implement Const type to indicate non-rebindable variables/attributes","articleBody":"As a Python developer, I would like a _Const_ type so that I can indicate that a variable or attribute may not be rebound to another value. This would be especially useful for module and class constants, but could also be helpful for instance attributes that really shouldn't be modified. Not only does it help prevent accidentally overwriting constants, it would hopefully reduce the need to use `@property` on non-critical attributes. Here is a contrived example:\n\n``` python\nGRUNT = 0 # type: Const\nMANAGER = 1 # type: Const\n\n\nclass Employee:\n kind = GRUNT # type: Const\n\n def __init__(self, idnum: int, name: str):\n self.id = idnum # type: Const\n self.name = name\n\n\nclass Manager(Employee):\n kind = MANAGER # type: Const\n```\n\n`kind = MANAGER # type: Const` reqiures the _Const_ type to rebind _kind_ without an error just as a const variable in C requires a cast during reassignment to quiet compiler warnings/errors.\n\nI'm not sure if it makes sense to allow _Const_ to take parameters as the type can be inferred in most cases. One might want other variables, such as those passed into functions, to be const, in which case it makes sense to allow _Const_ to take parameters. Here is an example:\n\n``` python\ndef frobnicate(kind: Const[int]) -> None:\n kind = 5 # Error\n kind = 6 # type: Const # Okay\n```\n","author":{"url":"https://github.com/hashstat","@type":"Person","name":"hashstat"},"datePublished":"2016-02-11T20:59:41Z","url":"https://github.com/python/mypy/issues/1214"}
| 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:415eebc0-a730-a107-2588-72d71751f47e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88FC:196792:27DF565:346FA8A:6B000A66 |
| html-safe-nonce | 04814b3253b746f5fce01dfcce115630ccf8f0ff3db4c2b29c4b1d9abde8dd96 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEZDOjE5Njc5MjoyN0RGNTY1OjM0NkZBOEE6NkIwMDBBNjYiLCJ2aXNpdG9yX2lkIjoiNDc3NTExMDIyNTkxNTAyMTkyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3855f20d1875594964156322d585465ee4926a9d43ac6643ebbac7b31f26d2d9 |
| hovercard-subject-tag | issue:133086376 |
| 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/1214/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4fc60596fcf1658cea115e0437b4aa5346736f617cc1e5fde823b3d59d03ebd1/python/mypy/issues/1214 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4fc60596fcf1658cea115e0437b4aa5346736f617cc1e5fde823b3d59d03ebd1/python/mypy/issues/1214 |
| og:image:alt | As a Python developer, I would like a Const type so that I can indicate that a variable or attribute may not be rebound to another value. This would be especially useful for module and class consta... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hashstat |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width