Use a hack to make typing of pytest.fail.Exception & co work #6758
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Mypy currently is unable to handle assigning attributes on function: python/mypy#2087.
pytest uses this for the outcome exceptions --
pytest.fail.Exception
,pytest.exit.Exception
etc, and this is the canonical name by which they are referred.Initially we started working around this with type: ignores, and later by switching e.g.
pytest.fail.Exception
with the direct exceptionFailed
. But this causes a lot of churn and is not as nice. And I also found that some code relies on it, in skipping.py:So it seems better to support it. Use a hack to make it work. The rest of the commit rolls back all of the workarounds we added up to now.
pytest.raises.Exception
also exists, but it's not used much so I kept it as-is for now.Hopefully in the future mypy supports this and this ugliness can be removed.