Title: mypy interprets arguments which contains a pipe to Literal as type strings instead of literals · Issue #16367 · python/mypy · GitHub
Open Graph Title: mypy interprets arguments which contains a pipe to Literal as type strings instead of literals · Issue #16367 · python/mypy
X Title: mypy interprets arguments which contains a pipe to Literal as type strings instead of literals · Issue #16367 · python/mypy
Description: Playground: from typing import Literal def f(v: Literal['foo', 'bar', 'foo|bar']) -> None: ... Expected behavior: f('foo') # Pass f('bar') # Pass f('foo|bar') # Pass f('baz') # Fail f('foo|') # Fail f('|qux') # Fail f('foo|qux') # Fail A...
Open Graph Description: Playground: from typing import Literal def f(v: Literal['foo', 'bar', 'foo|bar']) -> None: ... Expected behavior: f('foo') # Pass f('bar') # Pass f('foo|bar') # Pass f('baz') # Fail f('foo|') # Fai...
X Description: Playground: from typing import Literal def f(v: Literal['foo', 'bar', 'foo|bar']) -> None: ... Expected behavior: f('foo') # Pass f('bar') # Pass f('f...
Opengraph URL: https://github.com/python/mypy/issues/16367
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mypy interprets arguments which contains a pipe to Literal as type strings instead of literals","articleBody":"[Playground](https://mypy-play.net/?mypy=master&python=3.12&flags=strict&gist=df978698d4904f2fd0cd5a0beb66f196):\r\n\r\n```python\r\nfrom typing import Literal\r\n\r\n\r\ndef f(v: Literal['foo', 'bar', 'foo|bar']) -> None:\r\n ...\r\n```\r\n\r\nExpected behavior:\r\n\r\n```python\r\nf('foo') # Pass\r\nf('bar') # Pass\r\nf('foo|bar') # Pass\r\nf('baz') # Fail\r\nf('foo|') # Fail\r\nf('|qux') # Fail\r\nf('foo|qux') # Fail\r\n```\r\n\r\nActual behaviour:\r\n\r\n```py\r\ndef f(v: Literal['foo', 'bar', 'foo|bar']) -> None: # error: Name \"foo\" is not defined [name-defined]\r\n ...\r\n```\r\n\r\nEnvironment:\r\n\r\n- Mypy version used: 1.4/1.5/1.6/master branch.\r\n- Mypy command-line flags: None.\r\n- Mypy configuration options from `mypy.ini` (and other config files): None.\r\n- Python version used: 3.8/3.9/3.10/3.11/3.12.\r\n\r\nThis bug is found by StackOverflow user [Håkon T.](https://stackoverflow.com/users/3887338/h%c3%a5kon-t) at [this question](https://stackoverflow.com/q/77385142).\r\n\r\nIt seems that mypy would try to interpret any string containing a pipe (`|`) as a type, and in this case it failed.","author":{"url":"https://github.com/InSyncWithFoo","@type":"Person","name":"InSyncWithFoo"},"datePublished":"2023-10-29T21:27:06Z","url":"https://github.com/python/mypy/issues/16367"}
| 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:a0a19e38-40f2-77fd-4067-c92b196d64b8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D884:1F52F6:97140E:CA6E6C:6B004457 |
| html-safe-nonce | 428db16edb2d9d261ba37a0d6d4798fd292de9da28e17e07fa6845e94014eae9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODg0OjFGNTJGNjo5NzE0MEU6Q0E2RTZDOjZCMDA0NDU3IiwidmlzaXRvcl9pZCI6IjU0NTQ2NDkxNTgyMzUzNDE5MTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c63883876eb61565f0e6bb6ee3eb43fb6f578373ba0d84c581ab54d8b0c65b22 |
| hovercard-subject-tag | issue:1967160771 |
| 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/16367/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7ade48cad68b6cda25de2a7ee36ea56a3cd8b642e7e36226f7701eddfffa6207/python/mypy/issues/16367 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7ade48cad68b6cda25de2a7ee36ea56a3cd8b642e7e36226f7701eddfffa6207/python/mypy/issues/16367 |
| og:image:alt | Playground: from typing import Literal def f(v: Literal['foo', 'bar', 'foo|bar']) -> None: ... Expected behavior: f('foo') # Pass f('bar') # Pass f('foo|bar') # Pass f('baz') # Fail f('foo|') # Fai... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | InSyncWithFoo |
| 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