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

Added checks for invalid usage of continue/break/return in except* block #18132

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

coldwolverine
Copy link

Fixes #18123

This PR addresses an issue where mypy incorrectly allows break/continue/return statements in the except* block. (see https://peps.python.org/pep-0654/#forbidden-combinations)

This comment has been minimized.

Copy link
Collaborator

@brianschubert brianschubert left a comment

Choose a reason for hiding this comment

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

Nice! This looks good overall.

A few comments for you to consider, plus one issue that needs to be fixed in the tests:

mypy/semanal.py Outdated Show resolved Hide resolved
mypy/semanal.py Outdated Show resolved Hide resolved
test-data/unit/check-except-star.test Outdated Show resolved Hide resolved
test-data/unit/check-except-star.test Outdated Show resolved Hide resolved

This comment has been minimized.

@coldwolverine
Copy link
Author

Thanks for the comments! I've pushed a commit with all the changes.

This comment has been minimized.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Looks good, just a few minor comments.

mypy/semanal.py Outdated Show resolved Hide resolved
mypy/semanal.py Outdated Show resolved Hide resolved
mypy/semanal.py Outdated Show resolved Hide resolved
mypy/semanal.py Outdated Show resolved Hide resolved
mypy/semanal.py Outdated Show resolved Hide resolved
Comment on lines 227 to 229
from typing import Sequence
class range(Sequence[int]):
def __init__(self, __x: int, __y: int = ..., __z: int = ...) -> None: pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be replaced by a dummy list?

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

mypy doesn't flag continue/break/return in except*
3 participants