Skip to content

Mypy see invalid syntax about valid syntax in recent Python version #17914

@buxx

Description

@buxx

Bug Report

Mypy report a syntax error what is not in Python3.12+ while --python-version arg is used.

To Reproduce

This reproduction steps use uv to make python 3.12 install easier but got same result with standard tools.

➜  cd /tmp
➜  uv venv --python 3.12.6 venv                                              
Using Python 3.12.6
Creating virtual environment at: venv
Activate with: source venv/bin/activate
➜  . venv/bin/activate
(venv) ➜ uv pip install mypy
Resolved 3 packages in 139ms
Installed 3 packages in 22ms
 + mypy==1.11.2
 + mypy-extensions==1.0.0
 + typing-extensions==4.12.2
(venv) ➜  /tmp echo 'import typing               
import enum

class MyEnum(enum.Enum):
    ONE = "ONE"

    def name(self) -> str:
        match self:
            case self.ONE:
                return "1"
            case _:
                typing.assert_never(self)
' > test.py
(venv) ➜ mypy --python-version=3.12 test.py 
test.py:9: error: invalid syntax; you likely need to run mypy using Python 3.12 or newer  [syntax]
Found 1 error in 1 file (errors prevented further checking)

Expected Behavior

mypy don't see syntax error at line 9.

Actual Behavior

mypy see syntax error at line 9.

Your Environment

  • Mypy version used: 1.11.2
  • Mypy command-line flags: --python-version=3.12
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.12.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongpendingIssues that may be closed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions