-
Notifications
You must be signed in to change notification settings - Fork 141
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 annotate tests #592
type annotate tests #592
Conversation
Codecov Report
@@ Coverage Diff @@
## master #592 +/- ##
==========================================
- Coverage 79.08% 79.05% -0.04%
==========================================
Files 13 13
Lines 2056 2053 -3
Branches 293 293
==========================================
- Hits 1626 1623 -3
Misses 322 322
Partials 108 108
Continue to review full report at Codecov.
|
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 - surprising the small coverage drop but this is a huge step forward into getting complete type coverage. Many thanks!
I look forward to a more type annotated pytest!
config_path.write_text("\n".join(config_lines), encoding="utf-8") | ||
sys.argv = ["bandersnatch", "-c", str(config_path), "mirror"] | ||
assert config_path.exists() | ||
main(asyncio.new_event_loop()) | ||
(homedir, master), kwargs = mirror_mock.call_args_list[0] | ||
|
||
assert "/srv/pypi" == homedir | ||
assert Path("/srv/pypi") == homedir |
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.
Thanks for this change on Mirror - just hope non fikeaystem objects can handle it - cc: @techalchemy
monkeypatch.chdir(tmpdir) | ||
with open("sample", "w") as f: | ||
f.write("bsdf") | ||
with rewrite("sample") as f: | ||
with rewrite("sample") as f: # 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.
What is the type error here ... weird. I’ll look after merge.
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 error is:
src/bandersnatch/tests/test_utils.py: note: In function "test_rewrite":
src/bandersnatch/tests/test_utils.py:74: error: Incompatible types in
assignment (expression has type "IO[Any]", variable has type "TextIO")
with rewrite("sample") as f:
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 problem is that the open() call above has the return type typing.TextIO
because mypy sees "w"
and returns a more specific type. The rewrite function can take any mode and then pass it along to tempfile.NamedTemporaryFile
. Since the mode is defined by a variable, mypy just sets the return type of tempfile.NamedTemporaryFile
and subsequently rewrite
to typing.IO[Any]
.¹
A solution that comes to mind is just adding a f: IO[Any]
or f: IO
type annotation before the first with statement so f
isn't inferred as a subclass (typing.TextIO
) of typing.IO
.
¹. Quoting from Guido van Rossum python/typeshed#1229 (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.
Can't trust that guy, but that's what I would have tried too. Thanks @ichard26
hi!
This PR contains my work towards closing #15 . All the main tests now pass mypy, except for the plugin tests which I will continue to work on. As discussed in #15, there are some
# type: ignore
s that need to be worked through at some point once pytest supports typing better.