Title: Cannot assign an `Optional[float]` to a `float` · Issue #10340 · python/mypy · GitHub
Open Graph Title: Cannot assign an `Optional[float]` to a `float` · Issue #10340 · python/mypy
X Title: Cannot assign an `Optional[float]` to a `float` · Issue #10340 · python/mypy
Description: I have the class below which can optionally take a tuple, which itself optionally has float members, so (1.0, 2.0), None, (1.0, None), etc are all valid inputs. I do checking in the class to see if None has been input, and ignore the inp...
Open Graph Description: I have the class below which can optionally take a tuple, which itself optionally has float members, so (1.0, 2.0), None, (1.0, None), etc are all valid inputs. I do checking in the class to see if...
X Description: I have the class below which can optionally take a tuple, which itself optionally has float members, so (1.0, 2.0), None, (1.0, None), etc are all valid inputs. I do checking in the class to see if...
Opengraph URL: https://github.com/python/mypy/issues/10340
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot assign an `Optional[float]` to a `float`","articleBody":"I have the class below which can optionally take a tuple, which itself optionally has float members, so `(1.0, 2.0)`, `None`, `(1.0, None)`, etc are all valid inputs.\r\n\r\nI do checking in the class to see if `None` has been input, and ignore the input in those cases, but mypy is saying `Optional[float]` and `float` are incompatible for these assignments.\r\n\r\nHow can I specify to mypy that I've done my due diligence in type checking the input?\r\n\r\n\r\n```py\r\n# foo.py\r\nfrom typing import Optional, Tuple\r\n\r\n\r\nclass Foo:\r\n def __init__(\r\n self, bounds: Optional[Tuple[Optional[float], Optional[float]]] = None\r\n ):\r\n self._lower_bound: float = float(\"-inf\")\r\n self._upper_bound: float = float(\"inf\")\r\n if bounds:\r\n if bounds[0]:\r\n self._lower_bound = bounds[0]\r\n if bounds[1]:\r\n self._upper_bound = bounds[1]\r\n\r\n\r\nFoo((1, 2))\r\n```\r\n\r\n```\r\n$ mypy foo.py\r\nfoo.py:12: error: Incompatible types in assignment (expression has type \"Optional[float]\", variable has type \"float\")\r\nfoo.py:14: error: Incompatible types in assignment (expression has type \"Optional[float]\", variable has type \"float\")\r\nFound 2 errors in 1 file (checked 1 source file)\r\n```\r\n\r\nI'm running mypy 0.812 with Python 3.8.5","author":{"url":"https://github.com/fpdotmonkey","@type":"Person","name":"fpdotmonkey"},"datePublished":"2021-04-19T00:26:07Z","url":"https://github.com/python/mypy/issues/10340"}
| 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:21e4a3b3-8597-4326-0f24-7e2f46c281bb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C2DA:102136:1049183:15D3544:6B005DD9 |
| html-safe-nonce | 751db7314e56bbb9f553660c6853d3767fd800eca39cef081052a7789ed2d002 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkRBOjEwMjEzNjoxMDQ5MTgzOjE1RDM1NDQ6NkIwMDVERDkiLCJ2aXNpdG9yX2lkIjoiMjQ5NDE4MjUxNTI1ODk3MzY1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4e131649d95dd25c9e31eb944d6bdd2b78c7786884fd8891defa9b6ea878baec |
| hovercard-subject-tag | issue:860805324 |
| 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/10340/issue_layout |
| twitter:image | https://opengraph.githubassets.com/acd21aff1062de4af6e639b27eac315e33ed7b751e0ef998b5512508c1706b57/python/mypy/issues/10340 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/acd21aff1062de4af6e639b27eac315e33ed7b751e0ef998b5512508c1706b57/python/mypy/issues/10340 |
| og:image:alt | I have the class below which can optionally take a tuple, which itself optionally has float members, so (1.0, 2.0), None, (1.0, None), etc are all valid inputs. I do checking in the class to see if... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fpdotmonkey |
| 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