-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 pytest.{exit,skip,fail,xfail,importorskip,warns,raises} #5593
Conversation
These don't exist in Python 3.
9881f44
to
fbb69c5
Compare
Codecov Report
@@ Coverage Diff @@
## features #5593 +/- ##
============================================
- Coverage 96.05% 96.04% -0.02%
============================================
Files 117 117
Lines 25652 25748 +96
Branches 2502 2505 +3
============================================
+ Hits 24641 24729 +88
- Misses 704 708 +4
- Partials 307 311 +4
Continue to review full report at Codecov.
|
extend-ignore adds ignores in addition to flake8's existing ignores. The default ignores currently are: E121,E123,E126,E226,E24,E704,W503,W504
fbb69c5
to
b769166
Compare
Updated per @asottile's comments. |
…ord arguments" This reverts commit dfe54cd. The idea in the commit was to simplify the code by removing the check and instead letting it TypeError which has the same effect. However this type error is caught by mypy, and rather than ignoring the error we think it's better and clearer to go back to the previous explicit check.
This way, in with pytest.raises(ValueError) as cm: ... cm.value is a ValueError and not a BaseException.
Mypy doesn't like calling __init__() in this way.
This way the ExceptionInfo generic parameter can be inferred from the passed-in exc_info. See for example the replaced cast().
b769166
to
11f1f79
Compare
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'm going to take the "better ask for forgiveness" approach and merge this given the approval from @asottile - please let me know if that's not appropriate. |
@bluetech should these go into |
@asottile Would you mind explaining the difference a bit more? CONTRIBUTING.md says
This doesn't fit any of the options exactly. From what I gather, master is used for patch releases, and it's better not to involve unrelated changes in that, no? |
hmm yeah that's a good point, our generally we use |
OK, got it. I have some more PRs planned - do you think I should prepare a PR for |
To kickstart the plan laid out in #3342 (comment), this adds type annotations to some of the more well-known pytest APIs.
The PR is split into commits for easier reviewing.
For
pytest.raises
, there are two approaches, one is more precise but a bit more complex, requiring generics. I first implement the simple approach, then switch to the more complex approach in the last commit, so that it can be more easily dropped if wanted.I guess at this point the pytest devs will want to chime in on whether they want to go down the static typing path :)