Title: False positive for lambda within a function · Issue #10426 · python/mypy · GitHub
Open Graph Title: False positive for lambda within a function · Issue #10426 · python/mypy
X Title: False positive for lambda within a function · Issue #10426 · python/mypy
Description: Related Bug Could be a duplicate of: #4297 Bug Report When running mypy with a function returning an Optional the contains of a lambda expression is interpreted as optional and a type error is raised To Reproduce Run mypy against the fol...
Open Graph Description: Related Bug Could be a duplicate of: #4297 Bug Report When running mypy with a function returning an Optional the contains of a lambda expression is interpreted as optional and a type error is rais...
X Description: Related Bug Could be a duplicate of: #4297 Bug Report When running mypy with a function returning an Optional the contains of a lambda expression is interpreted as optional and a type error is rais...
Opengraph URL: https://github.com/python/mypy/issues/10426
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positive for lambda within a function","articleBody":"**Related Bug**\r\n\r\nCould be a duplicate of:\r\n- https://github.com/python/mypy/issues/4297\r\n\r\n**Bug Report**\r\n\r\nWhen running mypy with a function returning an Optional the contains of a lambda expression is interpreted as optional and a type error is raised\r\n\r\n**To Reproduce**\r\n\r\nRun `mypy` against the following file:\r\n\r\n```python3\r\nfrom typing import Optional\r\n\r\nanimals = [\"cow\"]\r\n\r\n\r\ndef find1(name: str) -\u003e Optional[str]:\r\n return next(\r\n filter(\r\n lambda animal: animal.upper() == name,\r\n animals,\r\n ),\r\n None,\r\n )\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nNo type errors should be returned\r\n\r\n**Actual Behavior**\r\n\r\n```shell\r\n$ mypy bug.py\r\nbug.py:9: error: Item \"None\" of \"Optional[str]\" has no attribute \"upper\"\r\n```\r\n\r\nNOTE: Same error with returning \"Union[str, None]\"\r\nNOTE: Removing the Optional[str] stops the error, but that defaults the point \r\n\r\n```python3\r\ndef find1(name: str):\r\n return next(\r\n filter(\r\n lambda animal: animal.upper() == name,\r\n animals,\r\n ),\r\n None,\r\n )\r\n```\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.812\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.9.4\r\n- Operating system and version: MacOS 10.15.7\r\n","author":{"url":"https://github.com/michaelbrewer","@type":"Person","name":"michaelbrewer"},"datePublished":"2021-05-06T04:03:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/10426/mypy/issues/10426"}
| 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:f722c901-0477-ed22-2ad5-54b701408ee9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 861C:1FC015:2149485:2CD92B2:6A5D71ED |
| html-safe-nonce | 9e796c3f9cac1b6e7c7780ceb91b60a7a177d4debf5a082e07ec65fbe2445ea5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjFDOjFGQzAxNToyMTQ5NDg1OjJDRDkyQjI6NkE1RDcxRUQiLCJ2aXNpdG9yX2lkIjoiNjY2ODcyNjA5MjI3MzkwNjE1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 07cdc7dc01891e76de8884e56eb0e6ec2ca06f1d5d11168f3605667ac9df4d68 |
| hovercard-subject-tag | issue:877050868 |
| 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/10426/issue_layout |
| twitter:image | https://opengraph.githubassets.com/05ff4cb0cb4f55552b1f100b68bca49f2fc2c078d827dd037d504531909d2b0c/python/mypy/issues/10426 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/05ff4cb0cb4f55552b1f100b68bca49f2fc2c078d827dd037d504531909d2b0c/python/mypy/issues/10426 |
| og:image:alt | Related Bug Could be a duplicate of: #4297 Bug Report When running mypy with a function returning an Optional the contains of a lambda expression is interpreted as optional and a type error is rais... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | michaelbrewer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width