-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
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.
Nice! This looks good overall.
A few comments for you to consider, plus one issue that needs to be fixed in the tests:
This comment has been minimized.
This comment has been minimized.
Thanks for the comments! I've pushed a commit with all the changes. |
…trol flow in except* block
This comment has been minimized.
This comment has been minimized.
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.
Looks good, just a few minor comments.
…e except* block, other minor fixes
for more information, see https://pre-commit.ci
test-data/unit/check-python311.test
Outdated
from typing import Sequence | ||
class range(Sequence[int]): | ||
def __init__(self, __x: int, __y: int = ..., __z: int = ...) -> None: pass |
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.
Can this be replaced by a dummy list?
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
The vast majority of mypy's code follows PEP 8 naming conventions. However, we currently don't enforce this in the linter config. I noticed this in a recent PR which included a `camelCase` name: #18132 (comment). Ruff has some rules to enforce PEP 8 naming style ([pep8-naming](https://docs.astral.sh/ruff/rules/#pep8-naming-n)). I think it would be a good idea to enable some of these to help contributors catch naming discrepancies before PR review. We have a few notable exceptions to PEP 8 naming (e.g. functions named to match ast node names), but these are easily accounted for with some config file ignores and handful of `# noqa`'s.
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)