Title: Mypy infers type var `E` as `Optional[E]` wrongly. · Issue #5049 · python/mypy · GitHub
Open Graph Title: Mypy infers type var `E` as `Optional[E]` wrongly. · Issue #5049 · python/mypy
X Title: Mypy infers type var `E` as `Optional[E]` wrongly. · Issue #5049 · python/mypy
Description: Mypy infers a type var E as Optional[E] wrongly. Input I tried type checking on the file as below with mypy --strict. #!/usr/bin/env python3 from typing import Callable from typing import Iterable from typing import Optional from typing ...
Open Graph Description: Mypy infers a type var E as Optional[E] wrongly. Input I tried type checking on the file as below with mypy --strict. #!/usr/bin/env python3 from typing import Callable from typing import Iterable ...
X Description: Mypy infers a type var E as Optional[E] wrongly. Input I tried type checking on the file as below with mypy --strict. #!/usr/bin/env python3 from typing import Callable from typing import Iterable ...
Opengraph URL: https://github.com/python/mypy/issues/5049
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypy infers type var `E` as `Optional[E]` wrongly.","articleBody":"Mypy infers a type var `E` as `Optional[E]` wrongly.\r\n\r\n\r\n## Input\r\n\r\nI tried type checking on the file as below with `mypy --strict`.\r\n\r\n```python\r\n#!/usr/bin/env python3\r\n\r\nfrom typing import Callable\r\nfrom typing import Iterable\r\nfrom typing import Optional\r\nfrom typing import TypeVar\r\n\r\nE = TypeVar('E')\r\n\r\n\r\ndef first(\r\n predicate: Callable[['E'], bool],\r\n iterable: Iterable['E'],\r\n) -> Optional['E']:\r\n for element in iterable:\r\n if predicate(element):\r\n return element\r\n return None\r\n\r\n\r\ndef test() -> Optional[int]:\r\n l = [0, 1, 2, 3]\r\n return first(lambda x: x > 1, l)\r\n```\r\n\r\n\r\n## Output (Mypy)\r\n\r\n### Expected \r\n\r\nI expect that type var `E` is inferred as `int` at the line 23 on the above file.\r\n\r\n\r\n## Actual\r\n\r\nI got an error from mypy as below:\r\n\r\n```\r\nfirst.py:23: error: Unsupported operand types for \u003c (\"int\" and \"Optional[int]\")\r\n```\r\n\r\n\r\n## Other Information\r\n\r\nI observed this behavior under the following environment:\r\n\r\n- CPython 3.6.5\r\n- Mypy 0.6000\r\n- macOS 10.13.4","author":{"url":"https://github.com/mitsuse","@type":"Person","name":"mitsuse"},"datePublished":"2018-05-15T05:50:23Z","url":"https://github.com/python/mypy/issues/5049"}
| 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:adf0c26a-4a2a-97ed-f14c-ef3b73595176 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9022:1334EF:D9E23F:11D20AB:6AFFFB7D |
| html-safe-nonce | 531634d8fd8ec5c44f5f02e64e98416c2c5d3d16e1ef90b2e345c6298a767904 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDIyOjEzMzRFRjpEOUUyM0Y6MTFEMjBBQjo2QUZGRkI3RCIsInZpc2l0b3JfaWQiOiI1MzU5OTE2MjE5OTMzNjUzODg1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1b6c1c5c7477b8ab845c6fb001df1447d42d8996b58cb0bfad072ac2511bc6a3 |
| hovercard-subject-tag | issue:323075138 |
| 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/5049/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1ca420f9821155c3fba20381ca526acbd540daf8090ead2e5b5c6fba921e3522/python/mypy/issues/5049 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1ca420f9821155c3fba20381ca526acbd540daf8090ead2e5b5c6fba921e3522/python/mypy/issues/5049 |
| og:image:alt | Mypy infers a type var E as Optional[E] wrongly. Input I tried type checking on the file as below with mypy --strict. #!/usr/bin/env python3 from typing import Callable from typing import Iterable ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mitsuse |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width