-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
type check in unit test #200
Conversation
UPDATE: resolved There are many errors like tianshou/policy/imitation/base.py:45: error: Return type "Dict[str, float]" of "learn" incompatible with return type "Dict[str, Union[float, List[float]]]" in supertype "BasePolicy" [override] Possibly a bug in mypy: from typing import Union
class A:
def test(self) -> Union[float, int]:
pass
class B(A):
def test(self) -> int:
pass This works in mypy check. However, from typing import Dict, Union
class A:
def test(self) -> Dict[str, Union[float, int]]:
pass
class B(A):
def test(self) -> Dict[str, int]:
pass This cannot pass the check: $ mypy try.py
try.py: note: In member "test" of class "B":
try.py:8: error: Return type "Dict[str, int]" of "test" incompatible with return type "Dict[str, Union[float, int]]" in supertype "A" [override]
Found 1 error in 1 file (checked 1 source file) However, here says narrow type in subclass is acceptable. |
Codecov Report
@@ Coverage Diff @@
## master #200 +/- ##
==========================================
+ Coverage 94.09% 94.42% +0.32%
==========================================
Files 40 39 -1
Lines 2457 2438 -19
==========================================
- Hits 2312 2302 -10
+ Misses 145 136 -9
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
My overall comment is that typing checking should make things more robust and clearer. It is clearly not the case at the current point, so I do not recommand satisfying all its recommendations at this point. Maybe it will get better in the future but it does not look viable for now. Just my opinion though. |
Agree most part. But I think it’s a tradeoff, especially in Python such a dynamic programming language. If we use other type checker, possibly the same things will happen again. Also, mypy is continuing improving, so I don’t pin a specific version and once the advanced features are added into mypy (like variable type re-definition), we can modify our code with minimal changes. |
Cherry-pick from #200 - update the function signature - format code-style - move _compile into separate functions - fix a bug in to_torch and to_numpy (Batch) - remove None in action_range In short, the code-format only contains function-signature style and `'` -> `"`. (pick up from [black](https://github.com/psf/black))
Cherry-pick from thu-ml#200 - update the function signature - format code-style - move _compile into separate functions - fix a bug in to_torch and to_numpy (Batch) - remove None in action_range In short, the code-format only contains function-signature style and `'` -> `"`. (pick up from [black](https://github.com/psf/black))
Fix thu-ml#195: Add mypy test in .github/workflows/docs_and_lint.yml. Also remove the out-of-the-date api
Fix #195: Add mypy test in
.github/workflows/docs_and_lint.yml
.Also remove the out-of-the-date api