Title: Literal types tracking issue · Issue #5935 · python/mypy · GitHub
Open Graph Title: Literal types tracking issue · Issue #5935 · python/mypy
X Title: Literal types tracking issue · Issue #5935 · python/mypy
Description: This issue tracks TODOs for literal types. Core work Modify the parser so it can handle literal expressions in types (#5947) Make any necessary changes to semantic analysis (see below) (#5947) Implement the core type-checking logic (also...
Open Graph Description: This issue tracks TODOs for literal types. Core work Modify the parser so it can handle literal expressions in types (#5947) Make any necessary changes to semantic analysis (see below) (#5947) Impl...
X Description: This issue tracks TODOs for literal types. Core work Modify the parser so it can handle literal expressions in types (#5947) Make any necessary changes to semantic analysis (see below) (#5947) Impl...
Opengraph URL: https://github.com/python/mypy/issues/5935
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Literal types tracking issue","articleBody":"This issue tracks TODOs for literal types.\r\n\r\n## Core work\r\n\r\n- [x] Modify the parser so it can handle literal expressions in types (https://github.com/python/mypy/pull/5947)\r\n- [x] Make any necessary changes to semantic analysis (see below) (https://github.com/python/mypy/pull/5947)\r\n- [x] Implement the core type-checking logic (also see below)\r\n- [x] Implement logic for determining when and when not to infer Literal (https://github.com/python/mypy/pull/5990)\r\n- [x] Validate that everything works in incremental mode and with the mypy daemon (https://github.com/python/mypy/pull/6075)\r\n- [ ] Add \"extra\" features (again see below)\r\n- [x] Write docs\r\n\r\n## Parsing/semantic analysis follow-up tasks\r\n\r\n- [x] Distinguish between byte strings, native strings, and unicode in Python 2 and Python 3 (https://github.com/python/mypy/pull/6087)\r\n- [x] Make sure everything still works with `from __future__ import unicode_literals` (https://github.com/python/mypy/pull/6087)\r\n- [x] Add more tests for forward references and related shenanigans\r\n- [x] Add logic to make sure literal expressions are coerced to the correct type based on context (https://github.com/python/mypy/pull/5990)\r\n\r\n## Error messages\r\n\r\n- [x] Add better error messages for complex numbers (https://github.com/python/mypy/pull/6149)\r\n- [x] Add better error messages for weird expressions in general (e.g. disallowing `Literal[1 + 2]`. This will probably involve moving *all* invalid type checking into the semantic analysis layer? (https://github.com/python/mypy/pull/6149)\r\n- [x] Resolve https://github.com/python/mypy/issues/5989 (https://github.com/python/mypy/pull/6149)\r\n\r\n## Implementing and testing type visitors\r\n\r\nImplement and write tests that exercise the following visitors. (Introduced by https://github.com/python/mypy/pull/5934)\r\n\r\n- [x] constraints.ConstraintBuilderVisitor (https://github.com/python/mypy/pull/5990)\r\n- [x] join.TypeJoinVisitor (https://github.com/python/mypy/pull/5990)\r\n- [x] meet.TypeMeetVisitor (https://github.com/python/mypy/pull/6043)\r\n- [x] subtypes.ProperSubtypeVisitor (https://github.com/python/mypy/pull/5947)\r\n- [x] subtypes.SubtypeVisitor (https://github.com/python/mypy/pull/5947)\r\n- [x] typeanal.TypeAnalyzer (https://github.com/python/mypy/pull/5947)\r\n- [x] typeanal.TypeAnalyzerPass3 (https://github.com/python/mypy/pull/5947)\r\n- [x] types.TypeStrVisitor (https://github.com/python/mypy/pull/5947)\r\n- [x] type_visitor.TypeVisitor (indirectly, by other tests)\r\n- [x] type_visitor.TypeTranslator (indirectly, by other tests)\r\n\r\nThe following have preliminary implementations, but are missing associated tests:\r\n\r\n- [x] erasetype.EraseTypeVisitor (indirectly, by https://github.com/python/mypy/pull/6035)\r\n- [x] expandtype.ExpandTypeVisitor (indirectly, by https://github.com/python/mypy/pull/6035)\r\n- [ ] fixup.TypeFixer (important for Enums)\r\n- [x] sametypes.SameTypeVisitor (https://github.com/python/mypy/pull/6043)\r\n- [x] server.astdiff.SnapshotTypeVisitor (https://github.com/python/mypy/pull/6075)\r\n- [x] server.deps.TypeTriggersVisitor (https://github.com/python/mypy/pull/6075)\r\n\r\n## Other checks to add in the type-checking layer\r\n\r\n- [x] Make sure we cannot subclass Literals (https://github.com/python/mypy/pull/6034)\r\n- [ ] Blacklist constructs like `Type[Literal[4]]`\r\n - Actually, should we? Maybe we should treat `Type[Literal[4]]` as `int` instead -- this might make certain TypeVar shenanigans more smooth. Need to discuss.\r\n - Actually, the above idea seems like a bad idea: if we do `x: Literal[3]`, doing `type(x)` ought to return a value with type `Type[int]`, not just `int`.\r\n- [x] Blacklist using `Literal[...]` in `isinstance` and `issubclass` checks (https://github.com/python/mypy/pull/6034)\r\n- [x] Validate `Literal` works as expected when used in generics (https://github.com/python/mypy/pull/6035)\r\n- [ ] Consider having mypy warn if somebody tries doing literally `TypeVar('T', bound=Literal[4])`? Need to discuss first.\r\n\r\n\r\n## \"Extra\" features to add\r\n\r\n- [x] Intelligent indexing of tuples, NamedTuples, TypedDict, getattr, and setattr (https://github.com/python/mypy/pull/6124)\r\n - While I'm at it, design a more intelligent \"macro replace\" system and try and fix the misc errors we get when using `--disallow-any-expr`?\r\n- [x] Type narrowing with equality and inequality checks\r\n- [x] Interactions with `Final` (https://github.com/python/mypy/pull/6081)\r\n- [x] Add custom type guards (see Ivan's comment below, also https://github.com/python/mypy/issues/5206)\r\n- [x] Treat bool as a union of `Literal[True]` and `Literal[False]` (see https://github.com/python/mypy/issues/6113)\r\n\r\n## Things to do before mypy 0.660 is released if literal types aren't going to make it\r\n\r\n- [x] Address https://github.com/python/mypy/issues/5989 -- restore old error messages, and expunge any reference to literal types in any error messages we added. (https://github.com/python/mypy/pull/6121)\r\n\r\n## Other things\r\n\r\n- [x] Try replacing one of the functions we currently manage using plugins with literal types instead, and see what happens.\r\n - I tried replacing the \"open(...)\" plugin and re-ran mypy on one of our smaller internal codebases. Out of approximately 680 calls to `open`, about 610 of them had 2 or more arguments. We inferred the correct type for about 560 of those. About another 20 of these were passing in string variable arguments as the mode. The remaining 30 require a little more investigation -- some people were passing in `**kwargs` or `**args` in as the argument, etc...\r\n\r\n## Things that have been deferred to after this project is completed\r\n\r\n- Adding support for enums in literal types (and while I'm at it, I might as well investigate overhauling enums in general). Related tasks:\r\n - Treat enum classes as roughly a union of their values\r\n - Better error messages for bad imports (e.g. enums with a coerced type of 'Any')\r\n- In error messages, we seem to quote types using either single quotes or double quotes. This can sometimes lead to messy-looking error messages (e.g. `Revealed type is 'Literal['foo']'`). We should standardize on a specific quoting scheme + avoid this weird \"nesting\" issue.\r\n- Make sure we report an error when somebody tries doing `Literal[3]()` (and `Final[int]()` and `Protocol[blah]()`...)\r\n","author":{"url":"https://github.com/Michael0x2a","@type":"Person","name":"Michael0x2a"},"datePublished":"2018-11-21T19:20:19Z","url":"https://github.com/python/mypy/issues/5935"}
| 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:28132358-74ec-f14b-780a-b54d687db5c1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE10:1F52F6:4EA504:69C54D:6B002FE3 |
| html-safe-nonce | 23494bdfa3863fe1cb61e902d838f4745cdb28f22940ea53fb9f59cf8812d02b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTEwOjFGNTJGNjo0RUE1MDQ6NjlDNTREOjZCMDAyRkUzIiwidmlzaXRvcl9pZCI6IjU2NTEwOTEwNzEwNDQ2OTM5ODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f3a0c653ed8a9355de8b646be126369574f3fa4efc8ff432b9feee8ab5f07b62 |
| hovercard-subject-tag | issue:383261076 |
| 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/5935/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3eabcf6f54a10e2f900240543ff3c99a263e3d1672502238375fc7c16d52e332/python/mypy/issues/5935 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3eabcf6f54a10e2f900240543ff3c99a263e3d1672502238375fc7c16d52e332/python/mypy/issues/5935 |
| og:image:alt | This issue tracks TODOs for literal types. Core work Modify the parser so it can handle literal expressions in types (#5947) Make any necessary changes to semantic analysis (see below) (#5947) Impl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Michael0x2a |
| 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