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

Mypy fails to typecheck itself following the recent black upgrade #16945

Closed
AlexWaygood opened this issue Feb 24, 2024 · 0 comments · Fixed by #16949
Closed

Mypy fails to typecheck itself following the recent black upgrade #16945

AlexWaygood opened this issue Feb 24, 2024 · 0 comments · Fixed by #16949
Labels
bug mypy got something wrong topic-developer Issues relevant to mypy developers

Comments

@AlexWaygood
Copy link
Member

Note: make sure you run mypy with a cold cache each time if you're trying to repro this bug locally. It seems to not always reproduce if you have a warm cache.

Bug Report

Following 8107e53 (bumping the version of black we use in CI to 24.1.1), mypy fails to typecheck its own codebase if you're using Python 3.10.6 or newer. This is a result of a CPython bug where the ast stdlib module on newer versions of Python thinks certain syntax around context managers is illegal on Python 3.8, even though that syntax works fine if you're actually using Python 3.8: python/cpython#115881.

Hopefully the CPython bug will be fixed, but it won't be backported to Python 3.10, since Python 3.10 is old enough that it now only accepts patches if they relate to security issues (and this bug isn't a security issue). If we want mypy to be able to typecheck itself using Python 3.10, we'll need to find a workaround.

To Reproduce

Inside a local clone of mypy, using Python 3.10.6 or newer, with all test requirements installed (including an editable install of mypy):

% rm -rf .mypy_cache
% python runtests.py self
run self: ['/Users/alexw/dev/mypy/310-6-venv/bin/python3', '-m', 'mypy', '--config-file', 'mypy_self_check.ini', '-p', 'mypy', '-p', 'mypyc']
mypy/checker.py:540: error: Parenthesized context managers are only supported in Python 3.9 and greater  [syntax]
                return True
                ^
mypy/checker.py:540: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-syntax for more info
Found 1 error in 1 file (errors prevented further checking)

FAILED: self

Expected Behavior

Mypy should be able to type-check its own codebase on all versions of Python

Actual Behavior

Mypy cannot typecheck its own codebase on newer versions of Python

Your Environment

  • Mypy version used: the mypy master branch
  • Python version used: I tested using Python 3.8, 3.9, 3.10.5, 3.10.6, 3.11.0 and 3.12.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-developer Issues relevant to mypy developers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant