Title: Treat ascii-only literals as str, not unicode when using `unicode_literals` · Issue #3619 · python/mypy · GitHub
Open Graph Title: Treat ascii-only literals as str, not unicode when using `unicode_literals` · Issue #3619 · python/mypy
X Title: Treat ascii-only literals as str, not unicode when using `unicode_literals` · Issue #3619 · python/mypy
Description: Many typeshed stubs only accept str when ascii-only unicode values also work at runtime. This causes a lot of problems with code using unicode_literals, since generally most literals will have unicode as their type. A quick fix would be ...
Open Graph Description: Many typeshed stubs only accept str when ascii-only unicode values also work at runtime. This causes a lot of problems with code using unicode_literals, since generally most literals will have unic...
X Description: Many typeshed stubs only accept str when ascii-only unicode values also work at runtime. This causes a lot of problems with code using unicode_literals, since generally most literals will have unic...
Opengraph URL: https://github.com/python/mypy/issues/3619
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Treat ascii-only literals as str, not unicode when using `unicode_literals`","articleBody":"Many typeshed stubs only accept `str` when ascii-only `unicode` values also work at runtime. This causes a lot of problems with code using `unicode_literals`, since generally most literals will have `unicode` as their type. A quick fix would be to infer `str` as the type for ascii-only string literals when using `unicode_literals`, but only then. This would cause some unsafety, but it may be worth it for users using `unicode_literals`. The type safe solution is to manually check every `str` argument type in the entire typeshed and potentially replace it with `unicode` or similar, but this would be extremely painful and unlikely to happen any time soon. This would have no effect on code that doesn't use `unicode_literals`.\r\n\r\nExample of how this would work:\r\n\r\n```py\r\nfrom __future__ import unicode_literals\r\n\r\nreveal_type('foo') # str\r\nreveal_type('ß') # unicode\r\n```\r\n\r\nSome open questions:\r\n* Should `u'foo'` always have type `unicode`?\r\n* What's the inferred type of `x` in `x = 'foo'`?\r\n","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2017-06-27T18:56:20Z","url":"https://github.com/python/mypy/issues/3619"}
| 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:2f31cab4-793e-11b4-3cb1-9c5e07f323ab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E902:2A8280:1F90A9:2C49D1:6B00580F |
| html-safe-nonce | e196a358e031a54cbf0b74a1a1f1880f76f9d10ce23eefa69947736aee671ee6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTAyOjJBODI4MDoxRjkwQTk6MkM0OUQxOjZCMDA1ODBGIiwidmlzaXRvcl9pZCI6IjcyOTg2OTkyMzM2OTgyNzMyOTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5531be6b1ab2f84d64fba34515aba553f4866bfb6f074ba45667f851ca76ad53 |
| hovercard-subject-tag | issue:238948791 |
| 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/3619/issue_layout |
| twitter:image | https://opengraph.githubassets.com/daa23fefccc0838f45a008a91b676397711cdd5cfb93a4acbd378c3692695ed7/python/mypy/issues/3619 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/daa23fefccc0838f45a008a91b676397711cdd5cfb93a4acbd378c3692695ed7/python/mypy/issues/3619 |
| og:image:alt | Many typeshed stubs only accept str when ascii-only unicode values also work at runtime. This causes a lot of problems with code using unicode_literals, since generally most literals will have unic... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JukkaL |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73 |
| 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 | eacd927ba6112e3b01ba99c762bd699a4a4f5df7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width