-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Handle empty bodies safely #13729
Handle empty bodies safely #13729
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
primer fallout seems really bad :-/ there's at least one fixable issue related to attrs, e.g. https://github.com/sco1/pylox/blob/393c029a8f503459e36367b990e43736f04bc5b9/pylox/tokens.py#L66
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
So I fixed the the plugin generated methods (now they don't require a body), and also allowed empty bodies if the return type is |
I think that it will be inevitable that this will generate some new errors, and it seems worth it since not having the checks has been a pretty big omission in mypy (of course assuming that they aren't false positives). |
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.
Looks great, just left some minor comments. This fixes a big safety hole in type checking. Thanks for carefully minimizing the fallout and false positives.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: ignite (https://github.com/pytorch/ignite)
+ ignite/contrib/handlers/tqdm_logger.py:226: error: Missing return statement [empty-body]
+ ignite/contrib/handlers/tqdm_logger.py:226: note: If the method is meant to be abstract, use @abc.abstractmethod
+ ignite/contrib/handlers/tqdm_logger.py:235: error: Missing return statement [empty-body]
+ ignite/contrib/handlers/tqdm_logger.py:235: note: If the method is meant to be abstract, use @abc.abstractmethod
artigraph (https://github.com/artigraph/artigraph)
+ tests/arti/producers/test_producer.py:34: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:34: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:34: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:38: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:38: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:104: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:104: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:104: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:118: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:118: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:118: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:129: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:129: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:129: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:143: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:143: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:143: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:155: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:155: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:155: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:170: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:170: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:170: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:181: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:181: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:181: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:191: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:191: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:191: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:253: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:253: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:253: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:257: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:257: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:269: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:269: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:269: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:371: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:371: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:376: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:376: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:376: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:388: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:388: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:388: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:398: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:398: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:398: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:421: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:421: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:421: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:431: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:431: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:431: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:435: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:435: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:448: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:448: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:448: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:466: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:466: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:554: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:554: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:554: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:566: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:566: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:566: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:573: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:573: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:585: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:585: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:594: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:594: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:594: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:604: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:604: note: Error code "empty-body" not covered by "type: ignore" comment
+ tests/arti/producers/test_producer.py:604: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:607: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:607: note: If the method is meant to be abstract, use @abc.abstractmethod
+ tests/arti/producers/test_producer.py:696: error: Missing return statement [empty-body]
+ tests/arti/producers/test_producer.py:696: note: If the method is meant to be abstract, use @abc.abstractmethod
Expression (https://github.com/cognitedata/Expression)
+ expression/core/typing.py:67: error: Missing return statement [empty-body]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/packaging/base.py:22: error: Missing return statement [empty-body]
+ src/prefect/packaging/base.py:22: note: If the method is meant to be abstract, use @abc.abstractmethod
+ src/prefect/packaging/base.py:25: error: Missing return statement [empty-body]
+ src/prefect/packaging/base.py:25: note: If the method is meant to be abstract, use @abc.abstractmethod
mypy (https://github.com/python/mypy)
+ mypy/visitor.py:363: error: Missing return statement [empty-body]
+ mypy/visitor.py:369: error: Missing return statement [empty-body]
+ mypy/visitor.py:374: error: Missing return statement [empty-body]
+ mypy/visitor.py:377: error: Missing return statement [empty-body]
+ mypy/visitor.py:380: error: Missing return statement [empty-body]
+ mypy/visitor.py:385: error: Missing return statement [empty-body]
+ mypy/visitor.py:388: error: Missing return statement [empty-body]
+ mypy/visitor.py:391: error: Missing return statement [empty-body]
+ mypy/visitor.py:394: error: Missing return statement [empty-body]
+ mypy/visitor.py:397: error: Missing return statement [empty-body]
+ mypy/visitor.py:400: error: Missing return statement [empty-body]
+ mypy/visitor.py:403: error: Missing return statement [empty-body]
+ mypy/visitor.py:406: error: Missing return statement [empty-body]
+ mypy/visitor.py:411: error: Missing return statement [empty-body]
+ mypy/visitor.py:414: error: Missing return statement [empty-body]
+ mypy/visitor.py:417: error: Missing return statement [empty-body]
+ mypy/visitor.py:420: error: Missing return statement [empty-body]
+ mypy/visitor.py:423: error: Missing return statement [empty-body]
+ mypy/visitor.py:426: error: Missing return statement [empty-body]
+ mypy/visitor.py:429: error: Missing return statement [empty-body]
+ mypy/visitor.py:432: error: Missing return statement [empty-body]
+ mypy/visitor.py:435: error: Missing return statement [empty-body]
+ mypy/visitor.py:438: error: Missing return statement [empty-body]
+ mypy/visitor.py:441: error: Missing return statement [empty-body]
+ mypy/visitor.py:444: error: Missing return statement [empty-body]
+ mypy/visitor.py:447: error: Missing return statement [empty-body]
+ mypy/visitor.py:450: error: Missing return statement [empty-body]
+ mypy/visitor.py:453: error: Missing return statement [empty-body]
+ mypy/visitor.py:456: error: Missing return statement [empty-body]
+ mypy/visitor.py:459: error: Missing return statement [empty-body]
+ mypy/visitor.py:464: error: Missing return statement [empty-body]
+ mypy/visitor.py:467: error: Missing return statement [empty-body]
+ mypy/visitor.py:470: error: Missing return statement [empty-body]
+ mypy/visitor.py:473: error: Missing return statement [empty-body]
+ mypy/visitor.py:476: error: Missing return statement [empty-body]
+ mypy/visitor.py:479: error: Missing return statement [empty-body]
+ mypy/visitor.py:482: error: Missing return statement [empty-body]
+ mypy/visitor.py:485: error: Missing return statement [empty-body]
+ mypy/visitor.py:488: error: Missing return statement [empty-body]
+ mypy/visitor.py:491: error: Missing return statement [empty-body]
+ mypy/visitor.py:494: error: Missing return statement [empty-body]
+ mypy/visitor.py:497: error: Missing return statement [empty-body]
+ mypy/visitor.py:500: error: Missing return statement [empty-body]
+ mypy/visitor.py:503: error: Missing return statement [empty-body]
+ mypy/visitor.py:506: error: Missing return statement [empty-body]
+ mypy/visitor.py:509: error: Missing return statement [empty-body]
+ mypy/visitor.py:512: error: Missing return statement [empty-body]
+ mypy/visitor.py:515: error: Missing return statement [empty-body]
+ mypy/visitor.py:518: error: Missing return statement [empty-body]
+ mypy/visitor.py:521: error: Missing return statement [empty-body]
+ mypy/visitor.py:524: error: Missing return statement [empty-body]
+ mypy/visitor.py:527: error: Missing return statement [empty-body]
+ mypy/visitor.py:530: error: Missing return statement [empty-body]
+ mypy/visitor.py:533: error: Missing return statement [empty-body]
+ mypy/visitor.py:536: error: Missing return statement [empty-body]
+ mypy/visitor.py:539: error: Missing return statement [empty-body]
+ mypy/visitor.py:542: error: Missing return statement [empty-body]
+ mypy/visitor.py:545: error: Missing return statement [empty-body]
+ mypy/visitor.py:548: error: Missing return statement [empty-body]
+ mypy/visitor.py:551: error: Missing return statement [empty-body]
+ mypy/visitor.py:554: error: Missing return statement [empty-body]
+ mypy/visitor.py:557: error: Missing return statement [empty-body]
+ mypy/visitor.py:560: error: Missing return statement [empty-body]
+ mypy/visitor.py:563: error: Missing return statement [empty-body]
+ mypy/visitor.py:566: error: Missing return statement [empty-body]
+ mypy/visitor.py:569: error: Missing return statement [empty-body]
+ mypy/visitor.py:572: error: Missing return statement [empty-body]
+ mypy/visitor.py:575: error: Missing return statement [empty-body]
+ mypy/visitor.py:578: error: Missing return statement [empty-body]
+ mypy/visitor.py:581: error: Missing return statement [empty-body]
+ mypy/visitor.py:584: error: Missing return statement [empty-body]
+ mypy/visitor.py:587: error: Missing return statement [empty-body]
+ mypy/visitor.py:590: error: Missing return statement [empty-body]
+ mypy/visitor.py:593: error: Missing return statement [empty-body]
+ mypy/visitor.py:598: error: Missing return statement [empty-body]
+ mypy/visitor.py:601: error: Missing return statement [empty-body]
+ mypy/visitor.py:604: error: Missing return statement [empty-body]
+ mypy/visitor.py:607: error: Missing return statement [empty-body]
+ mypy/visitor.py:610: error: Missing return statement [empty-body]
+ mypy/visitor.py:613: error: Missing return statement [empty-body]
+ mypy/visitor.py:616: error: Missing return statement [empty-body]
+ mypy/visitor.py:619: error: Missing return statement [empty-body]
materialize (https://github.com/MaterializeInc/materialize)
+ misc/python/stubs/docker/__init__.py:20: error: Missing return statement [empty-body]
websockets (https://github.com/aaugustin/websockets)
+ src/websockets/extensions/base.py:21: error: Missing return statement [empty-body]
+ src/websockets/extensions/base.py:42: error: Missing return statement [empty-body]
+ src/websockets/extensions/base.py:64: error: Missing return statement [empty-body]
+ src/websockets/extensions/base.py:73: error: Missing return statement [empty-body]
+ src/websockets/extensions/base.py:105: error: Missing return statement [empty-body]
sublime_debugger (https://github.com/daveleroy/sublime_debugger)
+ modules/ui/html.py:98: error: Missing return statement [empty-body]
+ modules/dap/configuration.py:19: error: Missing return statement [empty-body]
+ modules/dap/configuration.py:41: error: Missing return statement [empty-body]
+ modules/debugger_output_panel.py:267: error: Missing return statement [empty-body]
rich (https://github.com/Textualize/rich)
+ rich/_null_file.py:62: error: Missing return statement [empty-body]
+ rich/_null_file.py:62: note: If the method is meant to be abstract, use @abc.abstractmethod
bandersnatch (https://github.com/pypa/bandersnatch)
+ src/bandersnatch_storage_plugins/s3.py: note: In member "get_flock_path" of class "S3Storage":
+ src/bandersnatch_storage_plugins/s3.py:162: error: Missing return statement [empty-body]
manticore (https://github.com/trailofbits/manticore)
+ manticore/wasm/structure.py:1949: error: Missing return statement [empty-body]
+ manticore/native/cpu/abstractcpu.py:271: error: Missing return statement [empty-body]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/series.py:4645: error: Missing return statement [empty-body]
+ pandas/core/frame.py:9404: error: Missing return statement [empty-body]
poetry (https://github.com/python-poetry/poetry)
+ src/poetry/packages/locker.py:473: error: Missing return statement [empty-body]
spark (https://github.com/apache/spark)
+ python/pyspark/sql/group.py:173: error: Missing return statement [empty-body]
+ python/pyspark/sql/group.py:204: error: Missing return statement [empty-body]
+ python/pyspark/sql/group.py:218: error: Missing return statement [empty-body]
+ python/pyspark/sql/group.py:266: error: Missing return statement [empty-body]
+ python/pyspark/sql/group.py:307: error: Missing return statement [empty-body]
+ python/pyspark/sql/group.py:353: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:91: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:98: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:105: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:112: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:120: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:127: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:134: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:141: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:148: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:155: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints_with_future_annotations.py:196: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:88: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:95: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:102: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:109: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:117: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:124: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:131: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:138: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:145: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:152: error: Missing return statement [empty-body]
+ python/pyspark/sql/tests/test_pandas_udf_typehints.py:193: error: Missing return statement [empty-body]
pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/hookspec.py:741: error: Missing return statement [empty-body]
+ src/_pytest/hookspec.py:770: error: Missing return statement [empty-body]
+ src/_pytest/hookspec.py:803: error: Missing return statement [empty-body]
+ src/_pytest/hookspec.py:883: error: Missing return statement [empty-body]
|
Since python/mypy#13729, mypy complains if a non-abstract function has a trivial body. Avoid this providing a dummy body.
Since python/mypy#13729, mypy complains if a non-abstract function has a trivial body. Avoid this providing a dummy body.
Fixes #2350
This essentially re-applies #8111 modulo various (logical) changes in master since then.The only important difference is that now I override few return-related error codes for empty bodies, to allow opting out easily in next few versions (I still keep the flag to simplify testing).