-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn for missing returns with explicit Any return types #16102
Conversation
As discussed in python#7511, mypy's `--warn-no-return` isn't really a question of type safety. It does however enforce a rule that is "dear to Guido's heart", and I think we should enforce it for functions that explicitly return Any as well. Fixes python#16095
This comment has been minimized.
This comment has been minimized.
Hmm, more hits than I was hoping for. Most of them are PEP 8 violations, the few that are not should straightforwardly be |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also test correct cases to be correct.
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
for more information, see https://pre-commit.ci
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine)
+ porcupine/_state.py:41: error: Missing return statement [return]
pylox (https://github.com/sco1/pylox)
+ pylox/callable.py:41: error: Missing return statement [return]
comtypes (https://github.com/enthought/comtypes)
+ comtypes/tools/tlbparser.py:583: error: Missing return statement [return]
jinja (https://github.com/pallets/jinja)
+ src/jinja2/utils.py:131: error: Missing return statement [return]
+ src/jinja2/visitor.py:44: error: Missing return statement [return]
zetta_utils (https://github.com/ZettaAI/zetta_utils)
+ zetta_utils/builder/build.py:100: error: Missing return statement [return]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/utilities/visualization.py:51: error: Missing return statement [return]
sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/util/display.py: note: In function "__call__":
+ sphinx/util/display.py:90:9: error: Missing return statement [return]
+ sphinx/testing/fixtures.py: note: In member "store" of class "SharedResult":
+ sphinx/testing/fixtures.py:43:5: error: Missing return statement [return]
graphql-core (https://github.com/graphql-python/graphql-core)
+ src/graphql/utilities/type_info.py:276: error: Missing return statement [return]
+ src/graphql/execution/execute.py:1805: error: Missing return statement [return]
vision (https://github.com/pytorch/vision)
+ torchvision/transforms/v2/_misc.py:106: error: Missing return statement [return]
+ torchvision/transforms/v2/_misc.py:166: error: Missing return statement [return]
sublime_debugger (https://github.com/daveleroy/sublime_debugger)
+ modules/core/sublime.py:71: error: Missing return statement [return]
+ modules/output_panel.py:328: error: Missing return statement [return]
+ modules/adapters/js.py:64: error: Missing return statement [return]
bandersnatch (https://github.com/pypa/bandersnatch)
+ src/bandersnatch/master.py: note: In member "rpc" of class "Master":
+ src/bandersnatch/master.py:191: error: Missing return statement [return]
spark (https://github.com/apache/spark)
+ python/pyspark/sql/types.py:1161: error: Missing return statement [return]
+ python/pyspark/sql/types.py:1165: error: Missing return statement [return]
+ python/pyspark/ml/torch/data.py:38: error: Missing return statement [return]
+ python/pyspark/sql/connect/client/reattach.py:299: error: Missing return statement [return]
+ python/pyspark/pandas/frame.py:13243: error: Missing return statement [return]
+ python/pyspark/pandas/resample.py:736: error: Missing return statement [return]
+ python/pyspark/pandas/resample.py:768: error: Missing return statement [return]
schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/parameters.py: note: In member "example" of class "PayloadAlternatives":
+ src/schemathesis/parameters.py:92: error: Missing return statement [return]
+ src/schemathesis/specs/openapi/parameters.py: note: In member "example" of class "OpenAPIParameter":
+ src/schemathesis/specs/openapi/parameters.py:26: error: Missing return statement [return]
ignite (https://github.com/pytorch/ignite)
+ ignite/engine/engine.py:252: error: Missing return statement [return]
+ ignite/distributed/auto.py:354: error: Missing return statement [return]
+ ignite/contrib/handlers/neptune_logger.py:163: error: Missing return statement [return]
pandera (https://github.com/pandera-dev/pandera)
+ pandera/decorators.py:613: error: Missing return statement [return]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ gridfs/grid_file.py: note: In function "_grid_in_property":
+ gridfs/grid_file.py:73: error: Missing return statement [return]
pydantic (https://github.com/samuelcolvin/pydantic)
+ pydantic/main.py:782: error: Missing return statement [return]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/test_utils.py:611:5: error: Missing return statement [return]
+ aiohttp/test_utils.py:611:5: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-return for more info
streamlit (https://github.com/streamlit/streamlit)
+ lib/tests/streamlit/external/langchain/capturing_callback_handler.py: note: In member "on_agent_action" of class "CapturingCallbackHandler":
+ lib/tests/streamlit/external/langchain/capturing_callback_handler.py:196:5: error: Missing return statement [return]
+ lib/streamlit/external/langchain/streamlit_callback_handler.py: note: In member "on_agent_action" of class "StreamlitCallbackHandler":
+ lib/streamlit/external/langchain/streamlit_callback_handler.py:383:5: error: Missing return statement [return]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/trackref.py:58: error: Missing return statement [return]
discord.py (https://github.com/Rapptz/discord.py)
+ discord/ext/commands/context.py:544: error: Missing return statement [return]
+ discord/ext/commands/cooldowns.py:64: error: Missing return statement [return]
+ discord/ext/commands/hybrid.py:133: error: Missing return statement [return]
urllib3 (https://github.com/urllib3/urllib3)
+ test/test_wait.py:111: error: Missing return statement [return]
+ test/test_wait.py:142: error: Missing return statement [return]
+ test/test_wait.py:176: error: Missing return statement [return]
|
bump this |
I think this is too disruptive for too little benefit |
As discussed in #7511, mypy's
--warn-no-return
isn't really a question of type safety. It does however enforce a PEP 8 rule that is "dear to Guido's heart", and I think we should enforce it for functions that explicitly return Any as well.Fixes #16095