Title: MyPy gives error “Missing return statement” even when all cases are tested · Issue #4223 · python/mypy · GitHub
Open Graph Title: MyPy gives error “Missing return statement” even when all cases are tested · Issue #4223 · python/mypy
X Title: MyPy gives error “Missing return statement” even when all cases are tested · Issue #4223 · python/mypy
Description: I haven't received any answers to the following StackOverflow post, so I thought I'd also post it here. I'm not sure if it's an actual bug or if it's just considered good practice to always have something like else: raise Exception at th...
Open Graph Description: I haven't received any answers to the following StackOverflow post, so I thought I'd also post it here. I'm not sure if it's an actual bug or if it's just considered good practice to always have so...
X Description: I haven't received any answers to the following StackOverflow post, so I thought I'd also post it here. I'm not sure if it's an actual bug or if it's just considered good practi...
Opengraph URL: https://github.com/python/mypy/issues/4223
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MyPy gives error “Missing return statement” even when all cases are tested","articleBody":"I haven't received any answers to the [following StackOverflow post](https://stackoverflow.com/questions/47149154/mypy-gives-error-missing-return-statement-even-when-all-cases-are-tested), so I thought I'd also post it here. I'm not sure if it's an actual bug or if it's just considered good practice to always have something like `else: raise Exception` at the end of `if / elif ` block.\r\n\r\n----\r\n\r\nI am getting a MyPy error \"Missing return statement\", even when I check for all possible cases inside a function.\r\n\r\nFor example, in the following code, MyPy is still giving me an error `\"9: error: Missing return statement\"`, even though `color` can only be `Color.RED`, `Color.GREEN`, or `Color.BLUE`, and I test all those cases!\r\n\r\n```python\r\nclass Color(enum.IntEnum):\r\n RED: int = 1\r\n GREEN: int = 2\r\n BLUE: int = 3\r\n\r\n\r\ndef test_enum(color: Color) -> str:\r\n if color == Color.RED:\r\n return \"red\"\r\n elif color == Color.GREEN:\r\n return \"green\"\r\n elif color == Color.BLUE:\r\n return \"blue\"\r\n```","author":{"url":"https://github.com/ostrokach","@type":"Person","name":"ostrokach"},"datePublished":"2017-11-08T15:56:25Z","url":"https://github.com/python/mypy/issues/4223"}
| 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:62cc28a3-9983-f692-fedf-6e62924d9437 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA14:3AC034:BAE337:FBC19F:6B004EDB |
| html-safe-nonce | c325071da02f80cb1bd395903f6bac20e3366914bb8fe8d794b3d75336a4459f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTE0OjNBQzAzNDpCQUUzMzc6RkJDMTlGOjZCMDA0RURCIiwidmlzaXRvcl9pZCI6IjQ5MTc0OTA2OTcxNTE2NDg5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a717d02cad7d1ce16070bf59cf04216b8c86a31aa73da01a04f90f60e0dafee4 |
| hovercard-subject-tag | issue:272250133 |
| 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/4223/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dd1c1a3821e4653fc6da0a70ee0d8762716ac383a49b02bdd67ae3eaba939096/python/mypy/issues/4223 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dd1c1a3821e4653fc6da0a70ee0d8762716ac383a49b02bdd67ae3eaba939096/python/mypy/issues/4223 |
| og:image:alt | I haven't received any answers to the following StackOverflow post, so I thought I'd also post it here. I'm not sure if it's an actual bug or if it's just considered good practice to always have so... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ostrokach |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| 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 | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width