Skip to content
Merged

py310+ #2001

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion bin/gen-pycodestyle-plugin
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 0 additions & 37 deletions src/flake8/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/flake8/discover_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/flake8/options/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions tests/integration/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

import importlib.metadata
import sys
from unittest import mock

import pytest
Expand Down Expand Up @@ -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([], [], []),
Expand Down
12 changes: 4 additions & 8 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand Down