Title: Provide option to warn about non-abstract empty functions · Issue #9772 · python/mypy · GitHub
Open Graph Title: Provide option to warn about non-abstract empty functions · Issue #9772 · python/mypy
X Title: Provide option to warn about non-abstract empty functions · Issue #9772 · python/mypy
Description: Feature According to the documentation for the --no-warn-no-return option: By default, mypy will generate errors when a function is missing return statements in some execution paths. The only exceptions are when: The function has a None ...
Open Graph Description: Feature According to the documentation for the --no-warn-no-return option: By default, mypy will generate errors when a function is missing return statements in some execution paths. The only excep...
X Description: Feature According to the documentation for the --no-warn-no-return option: By default, mypy will generate errors when a function is missing return statements in some execution paths. The only excep...
Opengraph URL: https://github.com/python/mypy/issues/9772
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Provide option to warn about non-abstract empty functions","articleBody":"**Feature**\r\n\r\nAccording to the documentation for the [`--no-warn-no-return`](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-warn-no-return) option:\r\n\r\n> By default, mypy will generate errors when a function is missing return statements in some execution paths. The only exceptions are when:\r\n>\r\n> * The function has a `None` or `Any` return type\r\n> * The function has an empty body or a body that is just ellipsis (`...`). Empty functions are often used for abstract methods.\r\n\r\nI propose that the second bullet point should _only_ apply to abstract methods. Functions and non-abstract methods with an empty body or a body that is just ellipsis should produce a \"Missing return statement\" error as usual.\r\n\r\nThis behavior could be controlled with a feature flag such as `--warn-no-return-empty`.\r\n\r\n**Pitch**\r\n\r\nApart from abstract methods, I don't see why empty functions/methods should be excluded from no-return checking. For example, the following function clearly does not satisfy its return type annotation:\r\n\r\n```\r\ndef return_a_string() -> str:\r\n pass\r\n```\r\n\r\nThe same reasoning applies to methods. An empty method may indicate a programming error such as a missing `@abstractmethod` annotation.\r\n\r\n```\r\nfrom abc import ABC, abstractmethod\r\nclass MyABC(ABC):\r\n @abstractmethod\r\n def return_an_int(self) -> int: ...\r\n\r\n # whoops, forgot to annotate with @abstractmethod\r\n def return_a_string(self) -> str: ...\r\n```","author":{"url":"https://github.com/nickgaya","@type":"Person","name":"nickgaya"},"datePublished":"2020-11-30T22:35:44Z","url":"https://github.com/python/mypy/issues/9772"}
| 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:07b8eb87-fdf8-39de-8f6c-9d60a69b25e4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA22:182C25:BE42FB:FEF3D2:6B004EDB |
| html-safe-nonce | e084988cf21f3f6c09fea951de12ee18ac883b7d2b0eb81ba34a130f54d48332 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTIyOjE4MkMyNTpCRTQyRkI6RkVGM0QyOjZCMDA0RURCIiwidmlzaXRvcl9pZCI6Ijc4Mzk3MDk2MjIyOTMyNTM4NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a30fc1b02c1df9743a9a2113e0e25b1d1ec0ea7202278dee68e28bd94d0fe86a |
| hovercard-subject-tag | issue:753853888 |
| 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/9772/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e04b79a32d42c381dbdd339a729c2e55b680ff1609fa5487a64f3701cc6ca7d7/python/mypy/issues/9772 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e04b79a32d42c381dbdd339a729c2e55b680ff1609fa5487a64f3701cc6ca7d7/python/mypy/issues/9772 |
| og:image:alt | Feature According to the documentation for the --no-warn-no-return option: By default, mypy will generate errors when a function is missing return statements in some execution paths. The only excep... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nickgaya |
| 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