Title: Check that literal strings/int/float belong to /is excluded from a set/range of values · Issue #4040 · python/mypy · GitHub
Open Graph Title: Check that literal strings/int/float belong to /is excluded from a set/range of values · Issue #4040 · python/mypy
X Title: Check that literal strings/int/float belong to /is excluded from a set/range of values · Issue #4040 · python/mypy
Description: It's a common practice to pass literal strings as arguments. In Python, it's even more important, as strings are often used instead of byte flags, constants or enums. You often end up checking if those literals are passed correctly so yo...
Open Graph Description: It's a common practice to pass literal strings as arguments. In Python, it's even more important, as strings are often used instead of byte flags, constants or enums. You often end up checking if t...
X Description: It's a common practice to pass literal strings as arguments. In Python, it's even more important, as strings are often used instead of byte flags, constants or enums. You often end up check...
Opengraph URL: https://github.com/python/mypy/issues/4040
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Check that literal strings/int/float belong to /is excluded from a set/range of values ","articleBody":"It's a common practice to pass literal strings as arguments. In Python, it's even more important, as strings are often used instead of byte flags, constants or enums.\r\n\r\nYou often end up checking if those literals are passed correctly so you can give some debug information: \r\n\r\n- sorry, the parameter mode except a string among \"started, paused, cancelled\";\r\n\r\n- you can only used an integer between 0 and 16.\r\n\r\netc.\r\n\r\nThe problem with that is it's done at runtime despite the fact those argument are completely static ones. So the IDE can't use this information to help you write code. Typically, I would have code completion and linting helping me with \"started/pause/cancelled\" if it was an enum, but not if it's a string.\r\n\r\nWith this concept I could do:\r\n\r\n```\r\nMODES = ('started', 'paused', 'cancelled')\r\nLEVELS = (\r\n range(0, 5),\r\n range(40, float('+inf')), \r\n)\r\n\r\ndef foo(mode: typing.Among(MODES), levels: typing.Among(LEVELS)):\r\n pass\r\n```\r\n\r\nSo that mypy could alert my users if they do:\r\n\r\n`def foo(\"Start\", 6):`\r\n\r\nOf course, it's only for strings/ints/floats literals, maybe bytes and tuple, as we need the information to be immutable and simple to be usable.","author":{"url":"https://github.com/sametmax","@type":"Person","name":"sametmax"},"datePublished":"2017-10-01T14:48:17Z","url":"https://github.com/python/mypy/issues/4040"}
| 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:3f955d3f-09a4-7ccc-1850-afe5c5210e48 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9060:22FAD4:4F0300:69D1DE:6B002F1C |
| html-safe-nonce | 079e4f2e8b874dd72998c6dc03dc6c1628f70cfc291873d64820bc6d372bf781 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDYwOjIyRkFENDo0RjAzMDA6NjlEMURFOjZCMDAyRjFDIiwidmlzaXRvcl9pZCI6IjgxMDc1ODEzNTk1NDA2Nzg0MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 99e4b959126b604ce32cbba9b077b6e43b94ffd3c63dcd5923913ff1ee170e8e |
| hovercard-subject-tag | issue:261921366 |
| 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/4040/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8eda850c6be47453a8a468548c17557ae36e3f5ab7628644c817a9b15a35338d/python/mypy/issues/4040 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8eda850c6be47453a8a468548c17557ae36e3f5ab7628644c817a9b15a35338d/python/mypy/issues/4040 |
| og:image:alt | It's a common practice to pass literal strings as arguments. In Python, it's even more important, as strings are often used instead of byte flags, constants or enums. You often end up checking if t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sametmax |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width