-
Notifications
You must be signed in to change notification settings - Fork 281
Tests on the new implementation: address mypy warnings #1687
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
Tests on the new implementation: address mypy warnings #1687
Conversation
Pull Request Test Coverage Report for Build 1500766950Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
jku
left a comment
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.
Quick comments:
- Can you leave comments explaining the ignores -- they don't seem entirely obvious at first glance?
- Are requests and dateutil really not annotated anywhere ? I wonder how this has not been an issue so far but now requires ignores...
- test_fetcher (and as follow up tuf/requests_fetcher.py) should not need changing as they are part of legacy code
I mean PR comments, just for review |
| targets_key.verify_signature(md_obj, CanonicalJSONSerializer()) | ||
| with self.assertRaises(exceptions.UnsignedMetadataError): | ||
| targets_key.verify_signature(md_obj, JSONSerializer()) | ||
| targets_key.verify_signature(md_obj, JSONSerializer()) # type: ignore[arg-type] |
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.
Here we receive this warning:
tests/test_api.py:194: error: Argument 2 to "verify_signature" of "Key" has incompatible
type "JSONSerializer"; expected "Optional[SignedSerializer]" [arg-type]
I disabled it because the test wanted to test setting an explicit set serializer and which will raise
an UnsignedMetadataError and that's what happens.
Please note that JSONSerializer inherits the MetadataSerializer and not the SignedSerializer (as for example the CanonicalJSONSerializer does).
If we replace the JSONSerializer with the CanonicalJSONSerializer the test no longer passes
as we do that same thing on line 192.
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.
isn't this a sign of a bug somewhere then (presumably in the annotations since everything seems to work)?
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.
oh... you mean the test explicitly wants to use a serializer argument that is of a completely different class... but that just happens to have a method of same name serialize().
That's a weird test but not a bug then
| # Test wrong algorithm format (sslib.FormatError) | ||
| snapshot_metafile.hashes = { | ||
| 256: "8f88e2ba48b412c3843e9bb26e1b6f8fc9e98aceb0fbaa97ba37b4c98717d7ab" | ||
| 256: "8f88e2ba48b412c3843e9bb26e1b6f8fc9e98aceb0fbaa97ba37b4c98717d7ab" # type: ignore[dict-item] |
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.
Here we receive the following mypy warning:
tests/test_api.py:660: error: Dict entry 0 has incompatible type "int": "str";
expected "str": "str" [dict-item]
This error hints we have annotated the snapshot_metafile.hashes as a Dict[str, str], but we
are using it as Dict[int, str].
This is expected behavior here as we purposely test an invalid hash algorithm.
I left comments about each of them.
Hmm, I don't remember why I had to add them to the list in
I decided to add type annotations for them as I received warnings that I am calling unannotated code in annotated context. |
I would like to avoid touching any more legacy code at least in this PR than is necessary. However, I am interested in those warnings -- where do they come from? Why do we end up importing unannotated code that we did not expect to import? |
|
I removed all annotations added to The problem is that we are testing the request_fetcher inside a test for the newer implementation. |
2a83b1d to
b599b92
Compare
|
I updated the pr with:
|
jku
left a comment
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.
Wow, the lack of implicit None return value really makes this a big patch...
Good work: I left some comments but I don't think any are really required fixes. Take a look at the comments but I'm fine with merging as is.
By configuring mypy to show error codes when we get a warning by mypy we will receive an error code as well. Those error codes are useful when you want to disable specific mypy warning for a line with: Signed-off-by: Martin Vrachev <[email protected]>
In test_metadata_serialization.py "test_case_data" is actually a string when the decorator calls the actual test functions. Signed-off-by: Martin Vrachev <[email protected]>
Those tests are about missing "keys" and "roles" attributes in Targets.Delegations. Signed-off-by: Martin Vrachev <[email protected]>
This commit includes manual fixes for a lot of mypy warnings. When there were warnings that we are calling non-annotated function in annotated context I decided to add annotations instead of ignoring those warnings. That's how I end up adding annotations in the whole tests/utils.py module. Signed-off-by: Martin Vrachev <[email protected]>
b599b92 to
e2deff3
Compare
Fixes #1657
Related to #1582.
Description of the changes being introduced by the pull request:
This pr includes:
mypyto show error codesmypywarnings.When there were
mypywarnings that we are calling non-annotated functionin annotated context, I decided to add annotations instead of ignoring
those warnings.
That's how I end up adding annotations in the whole tests/utils.py
module.
NOTE: Those changes are not done by automatic tool, but instead are manual.
Please verify and check that the pull request fulfills the following
requirements: