Skip to content
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

Allow adding test cases testing version-dependent Python features #9238

Merged
merged 2 commits into from
Nov 21, 2022

Conversation

AlexWaygood
Copy link
Member

It's currently impossible to add a test case for ExceptionGroup or BaseExceptionGroup: see #9230. You'd think that you'd be able to just put the test behind an if sys.version_info >= (3, 11) guard, and pyright is indeed fine with that. Mypy, however, is not: when you run the test case with --python-version 3.10, it complains about many "unused type ignore" comments (it detects the type: ignore comments behind the if sys.version_info >= (3, 11) guard, even though it considers the whole block unreachable with --python-version 3.10, meaning it considers all type: ignores within that block to be "unused").

This PR works around that mypy annoyance. If this PR is merged, the test-case file can simply be renamed to be test_cases/stdlib/builtins/check_exception_group-py311.py, and python tests/regr_test.py --all should pass.

Cc. @sobolevn

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good work-around!
Ideally we can teach mypy not to trigger unused ignore on unreachable code as well.

Thanks!

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this won't work if we want test cases for things that were removed in a later version, but we'll have to figure out an approach for that when we get to it.

@JelleZijlstra JelleZijlstra merged commit 1f8491d into main Nov 21, 2022
@JelleZijlstra JelleZijlstra deleted the version-dependent-tests branch November 21, 2022 16:03
@AlexWaygood
Copy link
Member Author

I suppose this won't work if we want test cases for things that were removed in a later version, but we'll have to figure out an approach for that when we get to it.

Here's hoping nobody proposes to add test cases for things that have already been deprecated and removed in released versions of Python :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants