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 <xadupre@microsoft.com> * lint Signed-off-by: xadupre <xadupre@microsoft.com> * black Signed-off-by: xadupre <xadupre@microsoft.com> * black Signed-off-by: xadupre <xadupre@microsoft.com> * lint Signed-off-by: xadupre <xadupre@microsoft.com> * restore old import Signed-off-by: xadupre <xadupre@microsoft.com> Signed-off-by: xadupre <xadupre@microsoft.com>
Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com>
Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com>
Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com>
* primary ops to function milestone 1 Signed-off-by: Liqun Fu <liqfu@microsoft.com> * float type Signed-off-by: Liqun Fu <liqfu@microsoft.com> * formatting Signed-off-by: Liqun Fu <liqfu@microsoft.com> * pass backend test Signed-off-by: Liqun Fu <liqfu@microsoft.com> * formatting Signed-off-by: Liqun Fu <liqfu@microsoft.com> * commit Signed-off-by: Liqun Fu <liqfu@microsoft.com> * format Signed-off-by: Liqun Fu <liqfu@microsoft.com> * format Signed-off-by: Liqun Fu <liqfu@microsoft.com> * layernorm Signed-off-by: Liqun Fu <liqfu@microsoft.com> * pass runtime check Signed-off-by: Liqun Fu <liqfu@microsoft.com> * format Signed-off-by: Liqun Fu <liqfu@microsoft.com> * pure function Signed-off-by: Liqun Fu <liqfu@microsoft.com> * format Signed-off-by: Liqun Fu <liqfu@microsoft.com> * reviewer's comments, clean up some Signed-off-by: Liqun Fu <liqfu@microsoft.com> * keep op original version Signed-off-by: Liqun Fu <liqfu@microsoft.com> * fix gtest.function_verify_test Signed-off-by: Liqun Fu <liqfu@microsoft.com> * formatting Signed-off-by: Liqun Fu <liqfu@microsoft.com> * update according to reviewer's comment Signed-off-by: Liqun Fu <liqfu@microsoft.com> Signed-off-by: Liqun Fu <liqfu@microsoft.com> Co-authored-by: G. Ramalingam <grama@microsoft.com> Signed-off-by: xadupre <xadupre@microsoft.com>
Signed-off-by: xadupre <xadupre@microsoft.com>
…#4470) * apply filesystem from C+17 to handle encoding on Windows Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add comment in CMakeLists Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * precise msg if missing support Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * void normalize_sep for two types Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * remove typo const Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * remove template functions to header Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * apply clang-format Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * use _wstat Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * use define function to refactor code Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add required C++ version in readme Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * void char* for std::string in test Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * fix clang-format Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * move wchar_t and wstring only for Windows Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * refactor template Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * typo Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * use char tempalte in template Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add comments Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add tests for wstring Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * typo Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * nit comments Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * use existing functions from std::filesystem::path Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * honor != Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * constexpr const char Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * checker disallow absolute path in external tensors; remove related tests Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * fix format Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add more checker tests Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * black Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * improve comments Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com>
Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com>
Signed-off-by: xadupre <xadupre@microsoft.com>
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 <xadupre@microsoft.com> * lint Signed-off-by: xadupre <xadupre@microsoft.com> * black Signed-off-by: xadupre <xadupre@microsoft.com> * black Signed-off-by: xadupre <xadupre@microsoft.com> * lint Signed-off-by: xadupre <xadupre@microsoft.com> * restore old import Signed-off-by: xadupre <xadupre@microsoft.com> Signed-off-by: xadupre <xadupre@microsoft.com> * fix mypy issues Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com> * fix mypy issues Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com> * update mypy Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com> * primary ops to function milestone 1 (onnx#4458) * primary ops to function milestone 1 Signed-off-by: Liqun Fu <liqfu@microsoft.com> * float type Signed-off-by: Liqun Fu <liqfu@microsoft.com> * formatting Signed-off-by: Liqun Fu <liqfu@microsoft.com> * pass backend test Signed-off-by: Liqun Fu <liqfu@microsoft.com> * formatting Signed-off-by: Liqun Fu <liqfu@microsoft.com> * commit Signed-off-by: Liqun Fu <liqfu@microsoft.com> * format Signed-off-by: Liqun Fu <liqfu@microsoft.com> * format Signed-off-by: Liqun Fu <liqfu@microsoft.com> * layernorm Signed-off-by: Liqun Fu <liqfu@microsoft.com> * pass runtime check Signed-off-by: Liqun Fu <liqfu@microsoft.com> * format Signed-off-by: Liqun Fu <liqfu@microsoft.com> * pure function Signed-off-by: Liqun Fu <liqfu@microsoft.com> * format Signed-off-by: Liqun Fu <liqfu@microsoft.com> * reviewer's comments, clean up some Signed-off-by: Liqun Fu <liqfu@microsoft.com> * keep op original version Signed-off-by: Liqun Fu <liqfu@microsoft.com> * fix gtest.function_verify_test Signed-off-by: Liqun Fu <liqfu@microsoft.com> * formatting Signed-off-by: Liqun Fu <liqfu@microsoft.com> * update according to reviewer's comment Signed-off-by: Liqun Fu <liqfu@microsoft.com> Signed-off-by: Liqun Fu <liqfu@microsoft.com> Co-authored-by: G. Ramalingam <grama@microsoft.com> Signed-off-by: xadupre <xadupre@microsoft.com> * lint Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com> * remove # type: ignore for imports Signed-off-by: xadupre <xadupre@microsoft.com> * lint Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com> * 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 <jacky82226@gmail.com> * add comment in CMakeLists Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * precise msg if missing support Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * void normalize_sep for two types Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * remove typo const Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * remove template functions to header Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * apply clang-format Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * use _wstat Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * use define function to refactor code Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add required C++ version in readme Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * void char* for std::string in test Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * fix clang-format Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * move wchar_t and wstring only for Windows Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * refactor template Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * typo Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * use char tempalte in template Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add comments Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add tests for wstring Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * typo Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * nit comments Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * use existing functions from std::filesystem::path Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * honor != Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * constexpr const char Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * checker disallow absolute path in external tensors; remove related tests Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * fix format Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add more checker tests Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * black Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * improve comments Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com> * remove unnecessary ignore-missing-type Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: xadupre <xadupre@microsoft.com> * remove two type ignore Signed-off-by: xadupre <xadupre@microsoft.com> * lint Signed-off-by: xadupre <xadupre@microsoft.com> * type Signed-off-by: xadupre <xadupre@microsoft.com> Signed-off-by: xadupre <xadupre@microsoft.com> Signed-off-by: sdpython <xavier.dupre@gmail.com> Signed-off-by: Liqun Fu <liqfu@microsoft.com> Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> Co-authored-by: sdpython <xavier.dupre@gmail.com> Co-authored-by: liqun Fu <liqfu@microsoft.com> Co-authored-by: G. Ramalingam <grama@microsoft.com> Co-authored-by: Chun-Wei Chen <jacky82226@gmail.com>
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.