Title: Check that literal strings/int/float belong to /is excluded from a set/range of values · Issue #478 · python/typing · GitHub
Open Graph Title: Check that literal strings/int/float belong to /is excluded from a set/range of values · Issue #478 · python/typing
X Title: Check that literal strings/int/float belong to /is excluded from a set/range of values · Issue #478 · python/typing
Description: Opened in python/mypy#4040, but moved here after @JukkaL 's advice. Some debate took place in there, but I'll copy the original post here for context: It's a common practice to pass literal strings as arguments. In Python, it's even more...
Open Graph Description: Opened in python/mypy#4040, but moved here after @JukkaL 's advice. Some debate took place in there, but I'll copy the original post here for context: It's a common practice to pass literal strings...
X Description: Opened in python/mypy#4040, but moved here after @JukkaL 's advice. Some debate took place in there, but I'll copy the original post here for context: It's a common practice to pass lit...
Opengraph URL: https://github.com/python/typing/issues/478
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":"Opened in https://github.com/python/mypy/issues/4040, but moved here after @JukkaL 's advice.\r\n\r\nSome debate took place in there, but I'll copy the original post here for context:\r\n\r\n---\r\n\r\nIt'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-02T11:56:01Z","url":"https://github.com/python/typing/issues/478"}
| 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:0867c8e6-1719-2839-b0d9-0a6a23cb2a4b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B610:22BD05:213DC95:2D050B9:6B00219B |
| html-safe-nonce | 4e1561cbc686f4af756800d8d22e129b5ba191d32180611d9e4247ce85e1f590 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjEwOjIyQkQwNToyMTNEQzk1OjJEMDUwQjk6NkIwMDIxOUIiLCJ2aXNpdG9yX2lkIjoiNTk5MDg0ODE1MjY2NjY0NDg5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 55838fd06cdd60f8bea786acfb65fa4ff79b8c4b2f92c118540fa66538e48cb9 |
| hovercard-subject-tag | issue:262061173 |
| 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/478/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2a00dd1ef93fcf06e0df53e3b2b53e7518ce38e817034d5d1ae627e4e6e0c948/python/typing/issues/478 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2a00dd1ef93fcf06e0df53e3b2b53e7518ce38e817034d5d1ae627e4e6e0c948/python/typing/issues/478 |
| og:image:alt | Opened in python/mypy#4040, but moved here after @JukkaL 's advice. Some debate took place in there, but I'll copy the original post here for context: It's a common practice to pass literal strings... |
| 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 | 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