This commit is contained in:
Anthony Sottile 2025-10-16 10:01:02 -04:00
parent d45bdc05ce
commit 567cafc15a
9 changed files with 25 additions and 74 deletions

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -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

View file

@ -372,43 +372,6 @@ class FileChecker:
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:

View file

@ -3,9 +3,9 @@ from __future__ import annotations
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

View file

@ -5,9 +5,9 @@ import argparse
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

View file

@ -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", ("<unknown>", 2, 5, "bad python:\n"),
)
expected = (2, 4)
else: # pragma: no cover (3.10+)
err = SyntaxError(
"invalid syntax", ("<unknown>", 2, 1, "bad python:\n", 2, 11),
)
expected = (2, 1)
err = SyntaxError(
"invalid syntax", ("<unknown>", 2, 1, "bad python:\n", 2, 11),
)
expected = (2, 1)
file_checker = checker.FileChecker(
filename="-",
plugins=finder.Checkers([], [], []),

View file

@ -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 (<cp310)
expected = "t.py:3:5: E999 IndentationError: unindent does not match any outer indentation level\n" # noqa: E501
if sys.implementation.name == "pypy": # pragma: no cover (pypy)
expected = "t.py:3:3: E999 IndentationError: unindent does not match any outer indentation level\n" # noqa: E501
else: # pragma: no cover (cp310+)
expected = "t.py:3:7: E999 IndentationError: unindent does not match any outer indentation level\n" # noqa: E501