Skip to content

Mypy reports a missing return statement despite all cases of match statement return something #12071

@adonig

Description

@adonig

Bug Report

mypy reports a missing return statement despite all cases of a Python 3.10 match statement return something.

To Reproduce

Try this piece of code:

    def token_is_start_of_value(self) -> bool:
        """Check whether the current token is the start of a value.

        Returns:
            bool: True if the current token is the start of a value.
        """
        match self.token_type:
            case TokenType.DELIMITER if self.token in ("[", "{"):
                return True
            case TokenType.STRING | TokenType.NUMBER | TokenType.SYMBOL:
                return True
            case _:
                return False

Expected Behavior

mypy should not report a missing return statement.

Actual Behavior

mypy reports a missing return statement, see here:

Screen Shot 2022-01-25 at 21 29 01

Your Environment

  • Mypy version used: current master (0.940+dev.99f4d5af147d364eda1d4b99e79770c171896f13 99f4d5a)
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: Python 3.10.1
  • Operating system and version: macOS Monterey 12.0.1 (21A559)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-match-statementPython 3.10's match statement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions