From 567cafc15a0b20ad814579c17b306c058029334c Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 16 Oct 2025 10:01:02 -0400 Subject: [PATCH] py310+ --- .github/workflows/main.yml | 14 ++++++------ .pre-commit-config.yaml | 12 +++++----- bin/gen-pycodestyle-plugin | 2 +- setup.cfg | 2 +- src/flake8/checker.py | 37 ------------------------------- src/flake8/discover_files.py | 2 +- src/flake8/options/manager.py | 2 +- tests/integration/test_checker.py | 16 ++++--------- tests/integration/test_main.py | 12 ++++------ 9 files changed, 25 insertions(+), 74 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 08f54ea6..486b0cba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,10 +13,7 @@ jobs: include: # linux - os: ubuntu-latest - python: pypy-3.9 - toxenv: py - - os: ubuntu-latest - python: 3.9 + python: pypy-3.11 toxenv: py - os: ubuntu-latest python: '3.10' @@ -30,9 +27,12 @@ jobs: - os: ubuntu-latest python: '3.13' toxenv: py + - os: ubuntu-latest + python: '3.14' + toxenv: py # windows - os: windows-latest - python: 3.9 + python: '3.10' toxenv: py # misc - os: ubuntu-latest @@ -46,8 +46,8 @@ jobs: toxenv: dogfood runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} - run: python -mpip install --upgrade setuptools pip tox virtualenv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 20e006f6..2fac6b3f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/add-trailing-comma - rev: v3.2.0 + rev: v4.0.0 hooks: - id: add-trailing-comma - repo: https://github.com/pre-commit/pre-commit-hooks @@ -12,23 +12,23 @@ repos: - id: trailing-whitespace exclude: ^tests/fixtures/ - repo: https://github.com/asottile/setup-cfg-fmt - rev: v2.8.0 + rev: v3.1.0 hooks: - id: setup-cfg-fmt - repo: https://github.com/asottile/reorder-python-imports - rev: v3.15.0 + rev: v3.16.0 hooks: - id: reorder-python-imports args: [ --application-directories, '.:src', - --py39-plus, + --py310-plus, --add-import, 'from __future__ import annotations', ] - repo: https://github.com/asottile/pyupgrade - rev: v3.20.0 + rev: v3.21.0 hooks: - id: pyupgrade - args: [--py39-plus] + args: [--py310-plus] - repo: https://github.com/hhatto/autopep8 rev: v2.3.2 hooks: diff --git a/bin/gen-pycodestyle-plugin b/bin/gen-pycodestyle-plugin index c93fbfe1..7fc504ae 100755 --- a/bin/gen-pycodestyle-plugin +++ b/bin/gen-pycodestyle-plugin @@ -3,9 +3,9 @@ from __future__ import annotations import inspect import os.path +from collections.abc import Callable from collections.abc import Generator from typing import Any -from typing import Callable from typing import NamedTuple import pycodestyle diff --git a/setup.cfg b/setup.cfg index dc967d37..c0b8137d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,7 +30,7 @@ install_requires = mccabe>=0.7.0,<0.8.0 pycodestyle>=2.14.0,<2.15.0 pyflakes>=3.4.0,<3.5.0 -python_requires = >=3.9 +python_requires = >=3.10 package_dir = =src diff --git a/src/flake8/checker.py b/src/flake8/checker.py index d957915d..c6a24ebc 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -372,43 +372,6 @@ def _extract_syntax_information(exception: Exception) -> tuple[int, int]: token = () row, column = (1, 0) - if ( - column > 0 - and token - and isinstance(exception, SyntaxError) - and len(token) == 4 # Python 3.9 or earlier - ): - # NOTE(sigmavirus24): SyntaxErrors report 1-indexed column - # numbers. We need to decrement the column number by 1 at - # least. - column_offset = 1 - row_offset = 0 - # See also: https://github.com/pycqa/flake8/issues/169, - # https://github.com/PyCQA/flake8/issues/1372 - # On Python 3.9 and earlier, token will be a 4-item tuple with the - # last item being the string. Starting with 3.10, they added to - # the tuple so now instead of it ending with the code that failed - # to parse, it ends with the end of the section of code that - # failed to parse. Luckily the absolute position in the tuple is - # stable across versions so we can use that here - physical_line = token[3] - - # NOTE(sigmavirus24): Not all "tokens" have a string as the last - # argument. In this event, let's skip trying to find the correct - # column and row values. - if physical_line is not None: - # NOTE(sigmavirus24): SyntaxErrors also don't exactly have a - # "physical" line so much as what was accumulated by the point - # tokenizing failed. - # See also: https://github.com/pycqa/flake8/issues/169 - lines = physical_line.rstrip("\n").split("\n") - row_offset = len(lines) - 1 - logical_line = lines[0] - logical_line_length = len(logical_line) - if column > logical_line_length: - column = logical_line_length - row -= row_offset - column -= column_offset return row, column def run_ast_checks(self) -> None: diff --git a/src/flake8/discover_files.py b/src/flake8/discover_files.py index da28ba5d..40b6e5cc 100644 --- a/src/flake8/discover_files.py +++ b/src/flake8/discover_files.py @@ -3,9 +3,9 @@ import logging import os.path +from collections.abc import Callable from collections.abc import Generator from collections.abc import Sequence -from typing import Callable from flake8 import utils diff --git a/src/flake8/options/manager.py b/src/flake8/options/manager.py index addd3eca..ae407940 100644 --- a/src/flake8/options/manager.py +++ b/src/flake8/options/manager.py @@ -5,9 +5,9 @@ import enum import functools import logging +from collections.abc import Callable from collections.abc import Sequence from typing import Any -from typing import Callable from flake8 import utils from flake8.plugins.finder import Plugins diff --git a/tests/integration/test_checker.py b/tests/integration/test_checker.py index 60d01329..f7f07aff 100644 --- a/tests/integration/test_checker.py +++ b/tests/integration/test_checker.py @@ -2,7 +2,6 @@ from __future__ import annotations import importlib.metadata -import sys from unittest import mock import pytest @@ -322,17 +321,10 @@ def test_handling_syntaxerrors_across_pythons(): We need to handle that correctly to avoid crashing. https://github.com/PyCQA/flake8/issues/1372 """ - if sys.version_info < (3, 10): # pragma: no cover (<3.10) - # Python 3.9 or older - err = SyntaxError( - "invalid syntax", ("", 2, 5, "bad python:\n"), - ) - expected = (2, 4) - else: # pragma: no cover (3.10+) - err = SyntaxError( - "invalid syntax", ("", 2, 1, "bad python:\n", 2, 11), - ) - expected = (2, 1) + err = SyntaxError( + "invalid syntax", ("", 2, 1, "bad python:\n", 2, 11), + ) + expected = (2, 1) file_checker = checker.FileChecker( filename="-", plugins=finder.Checkers([], [], []), diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py index 5091573a..0ca5b63b 100644 --- a/tests/integration/test_main.py +++ b/tests/integration/test_main.py @@ -168,10 +168,8 @@ def test_tokenization_error_but_not_syntax_error(tmpdir, capsys): tmpdir.join("t.py").write("b'foo' \\\n") assert cli.main(["t.py"]) == 1 - if hasattr(sys, "pypy_version_info"): # pragma: no cover (pypy) - expected = "t.py:2:1: E999 SyntaxError: end of file (EOF) in multi-line statement\n" # noqa: E501 - elif sys.version_info < (3, 10): # pragma: no cover (cp38+) - expected = "t.py:1:8: E999 SyntaxError: unexpected EOF while parsing\n" + if sys.implementation.name == "pypy": # pragma: no cover (pypy) + expected = "t.py:1:9: E999 SyntaxError: unexpected end of file (EOF) in multi-line statement\n" # noqa: E501 else: # pragma: no cover (cp310+) expected = "t.py:1:10: E999 SyntaxError: unexpected EOF while parsing\n" # noqa: E501 @@ -186,10 +184,8 @@ def test_tokenization_error_is_a_syntax_error(tmpdir, capsys): tmpdir.join("t.py").write("if True:\n pass\n pass\n") assert cli.main(["t.py"]) == 1 - if hasattr(sys, "pypy_version_info"): # pragma: no cover (pypy) - expected = "t.py:3:2: E999 IndentationError: unindent does not match any outer indentation level\n" # noqa: E501 - elif sys.version_info < (3, 10): # pragma: no cover (