From 9e13708be845188424c718d3a3b26c2e6a4fd7a1 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 7 Sep 2024 16:41:06 -0700 Subject: [PATCH] Prevent use on Python 3.12.5 (#4447) Fixes #4446 See https://github.com/python/cpython/issues/123821 It's possible this is too strict? We could instead do this anytime the AST safety check fails, but feels weird to have that happen non-deterministically --- .github/workflows/doc.yml | 3 ++- .github/workflows/fuzz.yml | 2 +- .github/workflows/lint.yml | 3 ++- .github/workflows/pypi_upload.yml | 3 ++- .github/workflows/test.yml | 4 ++-- .github/workflows/upload_binary.yml | 2 +- CHANGES.md | 3 +++ src/black/__init__.py | 8 ++++++++ 8 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 4c592d7..901d435 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -26,7 +26,8 @@ jobs: - name: Set up latest Python uses: actions/setup-python@v5 with: - python-version: "*" + python-version: "3.13" + allow-prereleases: true - name: Install dependencies run: | diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index b3ea595..9d5f308 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12.4", "3.13"] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f757344..2d14092 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -26,7 +26,8 @@ jobs: - name: Set up latest Python uses: actions/setup-python@v5 with: - python-version: "*" + python-version: "3.13" + allow-prereleases: true - name: Install dependencies run: | diff --git a/.github/workflows/pypi_upload.yml b/.github/workflows/pypi_upload.yml index 7b363d8..ca548ec 100644 --- a/.github/workflows/pypi_upload.yml +++ b/.github/workflows/pypi_upload.yml @@ -23,7 +23,8 @@ jobs: - name: Set up latest Python uses: actions/setup-python@v5 with: - python-version: "*" + python-version: "3.13" + allow-prereleases: true - name: Install latest pip, build, twine run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0362087..5c8eb35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.9"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12.4", "3.13", "pypy-3.9"] os: [ubuntu-latest, macOS-latest, windows-latest] steps: @@ -99,7 +99,7 @@ jobs: - name: Set up latest Python uses: actions/setup-python@v5 with: - python-version: "*" + python-version: "3.12.4" - name: Install black with uvloop run: | diff --git a/.github/workflows/upload_binary.yml b/.github/workflows/upload_binary.yml index 06e55cf..1bde446 100644 --- a/.github/workflows/upload_binary.yml +++ b/.github/workflows/upload_binary.yml @@ -34,7 +34,7 @@ jobs: - name: Set up latest Python uses: actions/setup-python@v5 with: - python-version: "*" + python-version: "3.12.4" - name: Install Black and PyInstaller run: | diff --git a/CHANGES.md b/CHANGES.md index a83a4df..988c36e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,9 @@ - Black now officially supports Python 3.13 (#4436) +- Black will issue an error when used with Python 3.12.5, due to an upstream memory + safety issue in Python 3.12.5 that can cause Black's AST safety checks to fail. Please + use Python 3.12.6 or Python 3.12.4 instead. (#4447) ### Stable style diff --git a/src/black/__init__.py b/src/black/__init__.py index 942f316..7822e3d 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -549,6 +549,14 @@ def main( # noqa: C901 """The uncompromising code formatter.""" ctx.ensure_object(dict) + if sys.version_info[:3] == (3, 12, 5): + out( + "Python 3.12.5 has a memory safety issue that can cause Black's " + "AST safety checks to fail. " + "Please upgrade to Python 3.12.6 or downgrade to Python 3.12.4" + ) + ctx.exit(1) + if src and code is not None: out( main.get_usage(ctx)