-
Notifications
You must be signed in to change notification settings - Fork 649
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
Fix mypy errors #229
Fix mypy errors #229
Conversation
Returning a literal causes a mypy error when combined with the `typing.Optional[bool]` type hint. Furthermore, exception handling is the same when returning `False` and when returning `None` (the exception is re-raised). Therefore, it's simpler to remove the return statement and change the type hint to `None`.
Looks like there is another mypy error "hiding" behind this one. I'm looking into it. |
I wonder why this wasn't detected in the PR build. Maybe the CI is using different mypy versions on master vs branch builds? |
Yes, that seems to be a new requirement since mypy 0.740, see http://mypy-lang.blogspot.com/2019/10/mypy-0740-released.html The rationale seems to be that the I think we had some discussion about pinning tool/dependency versions but decided against it because we'd rather "stay up to date" and fix such errors. |
Tuples of length 1 should be initialized with a trailing comma to be properly interpreted.
Duplicated of #227? |
Thank you for battling mypy here and fixing bugs along the way! I think at this point, running mypy locally EDIT: Probably running |
Oops, thanks @mauriciovasquezbernal. In the meantime I've fixed all the errors in this PR, too. I've tried to solve the problems mypy is complaining about rather than ignoring them. Which option is the preferred one? |
Of course, I do that normally. In this case the changes in the newer mypy version threw me off so I didn't trust my local setup anymore :-) |
Since we have `disallow_untyped_calls = True` in our mypy config for tests, we must add type annotations to any function that is called from a test.
6dc1057
to
8dd4160
Compare
Done. |
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!
Hey, thanks for looking into this - I had myself ran |
I'll go ahead and merge this since it is likely uncontroversial and makes our master and all PR builds red. @carlosalberto: I think using |
Aaand, master is green again! 💚 |
In particular, the following errors are fixed in this commit: * Don't return False in __exit__ Returning a literal causes a mypy error when combined with the `typing.Optional[bool]` type hint. Furthermore, exception handling is the same when returning `False` and when returning `None` (the exception is re-raised). Therefore, it's simpler to remove the return statement and change the type hint to `None`. * Correctly initialize nested tuple Tuples of length 1 should be initialized with a trailing comma to be properly interpreted. * Pass correct type to use_context() in test * Add type annotations for test helper functions Since we have `disallow_untyped_calls = True` in our mypy config for tests, we must add type annotations to any function that is called from a test. Addditionally, bump minimal mypy version to 0.740 to consistently reproduce these errors.
* feat: add plugin config options * fix: resolve conflicts * fix: review comments
63f559e seems to have broken mypy since we are returning a literal
False
in 63f559e#diff-97345450e765fa40d32664356325e06cR248 while usingtyping.Optional[bool]
as the type hint.This causes the following mypy error:
I don't know why the CI was green on that commit, but anyway it is failing now.As it turns out we don't pin the mypy version so apparently this started breaking with mypy0.740
.AFAICT this can be solved by changing the type hint to
typing_extensions.Literal[False]
, however reading the docs it seems the only return value which suppresses exceptions isTrue
, therefore dropping the return statement altogether should have the same result as returning a literalFalse
and would also allow us to set the type hint to-> None
and fix mypy.