-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Reduces the number of ignored mypy errors #4495
Conversation
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.
I believe in the current codebase a lot of code cannot pass mypy 0.971 check. Currently two CIs are still running two different versions of mypy, which is quite confusing:
- mypy 0.782 in Linux-CI
- mypy 0.971 in Python Lint CI
It seems there is no way to specify mypy version from the latest action-mypy: tsuyoshicho/action-mypy#48. We probably can use an older version of tsuyoshicho/action-mypy, v2.0.1, which is using 0.790. If there are still a lot of existing errors with 0.790, I would suggest either we keep one version of mypy or upgrade mypy to the latest one (0.971). Upgrade mypy to the latest one will need a lot of fixes and perhaps the best we can do for now is only keeping version 0.782. @@justinchuby What's your thoughts on this? Thanks!
@@ -77,7 +77,7 @@ def _serialize(proto: Union[bytes, google.protobuf.message.Message]) -> bytes: | |||
"Please use save_as_external_data to save tensors separately from the model file." | |||
) from e | |||
raise | |||
return result | |||
return result # type: ignore |
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.
We should avoid ignores without error nums (too board)
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.
mypy returns Returning Any from function declared to return "bytes"
in this case. I assume SerializeToString() is annotated as Any when this function returns bytes. mypy detects the inconsistency. I don't think we can easliy remove it. I don't know if onnx is the source of the wrong annotation or if it is protobuf.
action-mypy uses the local mypy if found. We will simply need to install mypy at the version of our choice before running the check. |
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.
The part for adding ignore-missing-imports
makes sense to me. Thank you for updating so many places!
IMO we should be careful about adding more ignore conditions because it's hard to resolve every of them in the future when feasible. I saw a few places were added # type: ignore
so I would like to understand more details and whether we can resolve them properly.
onnx/backend/test/runner/__init__.py
Outdated
@@ -178,7 +178,7 @@ def tests(self) -> Type[unittest.TestCase]: | |||
onnx_backend_tests = BackendTest(backend).tests | |||
""" | |||
tests = self._get_test_case("OnnxBackendTest") | |||
for items_map in sorted(self._filtered_test_items.values()): | |||
for items_map in sorted(self._filtered_test_items.values()): # type: ignore |
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.
May I understand which kind of error does it ignore? mypy 0.971 produces: error: Value of type variable "SupportsRichComparisonT" of "sorted" cannot be "Dict[str, TestItem]" [type-var]
@@ -100,7 +100,7 @@ def _assert_inferred( | |||
inferred_model = self._inferred(graph, **kwargs) | |||
inferred_vis = list(inferred_model.graph.value_info) | |||
vis = list(sorted(vis, key=lambda x: x.name)) | |||
inferred_vis = list(sorted(inferred_vis, key=lambda x: x.name)) | |||
inferred_vis = list(sorted(inferred_vis, key=lambda x: x.name)) # type: ignore |
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.
May I understand which kind of error does it ignore? mypy 0.971 produces: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]" [no-any-return]
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.
I would still suggest adding the error code in square brackets to narrow the ignore for clarity.
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.
From what I understood, you can ignore this error by forcing the type: type: expected type
. But mypy checks the expected type
exists and for that it must have been imported. But if I do that, it would raise the warning unused import. So I think # type: ignore
is not bad here.
* remove unnecessary import Signed-off-by: xadupre <[email protected]> * lint Signed-off-by: xadupre <[email protected]> * black Signed-off-by: xadupre <[email protected]> * black Signed-off-by: xadupre <[email protected]> * lint Signed-off-by: xadupre <[email protected]> * restore old import Signed-off-by: xadupre <[email protected]> Signed-off-by: xadupre <[email protected]>
Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]>
Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]>
Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]>
* primary ops to function milestone 1 Signed-off-by: Liqun Fu <[email protected]> * float type Signed-off-by: Liqun Fu <[email protected]> * formatting Signed-off-by: Liqun Fu <[email protected]> * pass backend test Signed-off-by: Liqun Fu <[email protected]> * formatting Signed-off-by: Liqun Fu <[email protected]> * commit Signed-off-by: Liqun Fu <[email protected]> * format Signed-off-by: Liqun Fu <[email protected]> * format Signed-off-by: Liqun Fu <[email protected]> * layernorm Signed-off-by: Liqun Fu <[email protected]> * pass runtime check Signed-off-by: Liqun Fu <[email protected]> * format Signed-off-by: Liqun Fu <[email protected]> * pure function Signed-off-by: Liqun Fu <[email protected]> * format Signed-off-by: Liqun Fu <[email protected]> * reviewer's comments, clean up some Signed-off-by: Liqun Fu <[email protected]> * keep op original version Signed-off-by: Liqun Fu <[email protected]> * fix gtest.function_verify_test Signed-off-by: Liqun Fu <[email protected]> * formatting Signed-off-by: Liqun Fu <[email protected]> * update according to reviewer's comment Signed-off-by: Liqun Fu <[email protected]> Signed-off-by: Liqun Fu <[email protected]> Co-authored-by: G. Ramalingam <[email protected]> Signed-off-by: xadupre <[email protected]>
Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]>
…#4470) * apply filesystem from C+17 to handle encoding on Windows Signed-off-by: Chun-Wei Chen <[email protected]> * add comment in CMakeLists Signed-off-by: Chun-Wei Chen <[email protected]> * precise msg if missing support Signed-off-by: Chun-Wei Chen <[email protected]> * void normalize_sep for two types Signed-off-by: Chun-Wei Chen <[email protected]> * remove typo const Signed-off-by: Chun-Wei Chen <[email protected]> * remove template functions to header Signed-off-by: Chun-Wei Chen <[email protected]> * apply clang-format Signed-off-by: Chun-Wei Chen <[email protected]> * use _wstat Signed-off-by: Chun-Wei Chen <[email protected]> * use define function to refactor code Signed-off-by: Chun-Wei Chen <[email protected]> * add required C++ version in readme Signed-off-by: Chun-Wei Chen <[email protected]> * void char* for std::string in test Signed-off-by: Chun-Wei Chen <[email protected]> * fix clang-format Signed-off-by: Chun-Wei Chen <[email protected]> * move wchar_t and wstring only for Windows Signed-off-by: Chun-Wei Chen <[email protected]> * refactor template Signed-off-by: Chun-Wei Chen <[email protected]> * typo Signed-off-by: Chun-Wei Chen <[email protected]> * use char tempalte in template Signed-off-by: Chun-Wei Chen <[email protected]> * add comments Signed-off-by: Chun-Wei Chen <[email protected]> * add tests for wstring Signed-off-by: Chun-Wei Chen <[email protected]> * typo Signed-off-by: Chun-Wei Chen <[email protected]> * nit comments Signed-off-by: Chun-Wei Chen <[email protected]> * use existing functions from std::filesystem::path Signed-off-by: Chun-Wei Chen <[email protected]> * honor != Signed-off-by: Chun-Wei Chen <[email protected]> * constexpr const char Signed-off-by: Chun-Wei Chen <[email protected]> * checker disallow absolute path in external tensors; remove related tests Signed-off-by: Chun-Wei Chen <[email protected]> * fix format Signed-off-by: Chun-Wei Chen <[email protected]> * add more checker tests Signed-off-by: Chun-Wei Chen <[email protected]> * black Signed-off-by: Chun-Wei Chen <[email protected]> * improve comments Signed-off-by: Chun-Wei Chen <[email protected]> Signed-off-by: Chun-Wei Chen <[email protected]> Signed-off-by: xadupre <[email protected]>
Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
Signed-off-by: xadupre <[email protected]>
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.
LGTM. Thank you for enabling the latest mypy!
Thanks for fixing these! |
* Remove unnecessary import (onnx#4484) * remove unnecessary import Signed-off-by: xadupre <[email protected]> * lint Signed-off-by: xadupre <[email protected]> * black Signed-off-by: xadupre <[email protected]> * black Signed-off-by: xadupre <[email protected]> * lint Signed-off-by: xadupre <[email protected]> * restore old import Signed-off-by: xadupre <[email protected]> Signed-off-by: xadupre <[email protected]> * fix mypy issues Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]> * fix mypy issues Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]> * update mypy Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]> * primary ops to function milestone 1 (onnx#4458) * primary ops to function milestone 1 Signed-off-by: Liqun Fu <[email protected]> * float type Signed-off-by: Liqun Fu <[email protected]> * formatting Signed-off-by: Liqun Fu <[email protected]> * pass backend test Signed-off-by: Liqun Fu <[email protected]> * formatting Signed-off-by: Liqun Fu <[email protected]> * commit Signed-off-by: Liqun Fu <[email protected]> * format Signed-off-by: Liqun Fu <[email protected]> * format Signed-off-by: Liqun Fu <[email protected]> * layernorm Signed-off-by: Liqun Fu <[email protected]> * pass runtime check Signed-off-by: Liqun Fu <[email protected]> * format Signed-off-by: Liqun Fu <[email protected]> * pure function Signed-off-by: Liqun Fu <[email protected]> * format Signed-off-by: Liqun Fu <[email protected]> * reviewer's comments, clean up some Signed-off-by: Liqun Fu <[email protected]> * keep op original version Signed-off-by: Liqun Fu <[email protected]> * fix gtest.function_verify_test Signed-off-by: Liqun Fu <[email protected]> * formatting Signed-off-by: Liqun Fu <[email protected]> * update according to reviewer's comment Signed-off-by: Liqun Fu <[email protected]> Signed-off-by: Liqun Fu <[email protected]> Co-authored-by: G. Ramalingam <[email protected]> Signed-off-by: xadupre <[email protected]> * lint Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]> * remove # type: ignore for imports Signed-off-by: xadupre <[email protected]> * lint Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]> * Use filesystem to load filename to prevent encoding issues on Windows (onnx#4470) * apply filesystem from C+17 to handle encoding on Windows Signed-off-by: Chun-Wei Chen <[email protected]> * add comment in CMakeLists Signed-off-by: Chun-Wei Chen <[email protected]> * precise msg if missing support Signed-off-by: Chun-Wei Chen <[email protected]> * void normalize_sep for two types Signed-off-by: Chun-Wei Chen <[email protected]> * remove typo const Signed-off-by: Chun-Wei Chen <[email protected]> * remove template functions to header Signed-off-by: Chun-Wei Chen <[email protected]> * apply clang-format Signed-off-by: Chun-Wei Chen <[email protected]> * use _wstat Signed-off-by: Chun-Wei Chen <[email protected]> * use define function to refactor code Signed-off-by: Chun-Wei Chen <[email protected]> * add required C++ version in readme Signed-off-by: Chun-Wei Chen <[email protected]> * void char* for std::string in test Signed-off-by: Chun-Wei Chen <[email protected]> * fix clang-format Signed-off-by: Chun-Wei Chen <[email protected]> * move wchar_t and wstring only for Windows Signed-off-by: Chun-Wei Chen <[email protected]> * refactor template Signed-off-by: Chun-Wei Chen <[email protected]> * typo Signed-off-by: Chun-Wei Chen <[email protected]> * use char tempalte in template Signed-off-by: Chun-Wei Chen <[email protected]> * add comments Signed-off-by: Chun-Wei Chen <[email protected]> * add tests for wstring Signed-off-by: Chun-Wei Chen <[email protected]> * typo Signed-off-by: Chun-Wei Chen <[email protected]> * nit comments Signed-off-by: Chun-Wei Chen <[email protected]> * use existing functions from std::filesystem::path Signed-off-by: Chun-Wei Chen <[email protected]> * honor != Signed-off-by: Chun-Wei Chen <[email protected]> * constexpr const char Signed-off-by: Chun-Wei Chen <[email protected]> * checker disallow absolute path in external tensors; remove related tests Signed-off-by: Chun-Wei Chen <[email protected]> * fix format Signed-off-by: Chun-Wei Chen <[email protected]> * add more checker tests Signed-off-by: Chun-Wei Chen <[email protected]> * black Signed-off-by: Chun-Wei Chen <[email protected]> * improve comments Signed-off-by: Chun-Wei Chen <[email protected]> Signed-off-by: Chun-Wei Chen <[email protected]> Signed-off-by: xadupre <[email protected]> * remove unnecessary ignore-missing-type Signed-off-by: sdpython <[email protected]> Signed-off-by: xadupre <[email protected]> * remove two type ignore Signed-off-by: xadupre <[email protected]> * lint Signed-off-by: xadupre <[email protected]> * type Signed-off-by: xadupre <[email protected]> Signed-off-by: xadupre <[email protected]> Signed-off-by: sdpython <[email protected]> Signed-off-by: Liqun Fu <[email protected]> Signed-off-by: Chun-Wei Chen <[email protected]> Co-authored-by: sdpython <[email protected]> Co-authored-by: liqun Fu <[email protected]> Co-authored-by: G. Ramalingam <[email protected]> Co-authored-by: Chun-Wei Chen <[email protected]>
Description
Reduces the number of mypy errors. It works with the latest version of mypy. It adds the flag --ignore-missing-package to avoid adding
type: ignore
every timeimport numpy
is used. The PR removes unnecessary# type: ignore
every time an external package is imported.Motivation and Context
tools/style.sh generates many errors not related to the changes. This PR make it easier to read what is related to the user changes.