Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mypy doesn't flag continue/break/return in except* #18123

Description

@jakkdl

Feature
continue/break/return in except* is a syntax error, see https://peps.python.org/pep-0654/#forbidden-combinations.

def foo():
    for _ in range(5):
        try:
            ...
        except* Exception:
            continue
        except* ValueError:
            break
        except* TypeError:
            return
$ mypy --python-version=3.11 foo.py
Success: no issues found in 1 source file
$ mypy --version
mypy 1.13.0 (compiled: yes)

Pitch
mypy does give an error if you try to combine except and except*, and as far as I know it flags all other syntax errors as well, so should probably handle this too. It might also cause users to adjust code to avoid unreachable code needlessly, when in fact they have bigger problems to fix first.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions