mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 21:44:18 +00:00
commit
fcfa2cd490
9 changed files with 25 additions and 74 deletions
14
.github/workflows/main.yml
vendored
14
.github/workflows/main.yml
vendored
|
|
@ -13,10 +13,7 @@ jobs:
|
||||||
include:
|
include:
|
||||||
# linux
|
# linux
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
python: pypy-3.9
|
python: pypy-3.11
|
||||||
toxenv: py
|
|
||||||
- os: ubuntu-latest
|
|
||||||
python: 3.9
|
|
||||||
toxenv: py
|
toxenv: py
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
python: '3.10'
|
python: '3.10'
|
||||||
|
|
@ -30,9 +27,12 @@ jobs:
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
python: '3.13'
|
python: '3.13'
|
||||||
toxenv: py
|
toxenv: py
|
||||||
|
- os: ubuntu-latest
|
||||||
|
python: '3.14'
|
||||||
|
toxenv: py
|
||||||
# windows
|
# windows
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
python: 3.9
|
python: '3.10'
|
||||||
toxenv: py
|
toxenv: py
|
||||||
# misc
|
# misc
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
|
|
@ -46,8 +46,8 @@ jobs:
|
||||||
toxenv: dogfood
|
toxenv: dogfood
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python }}
|
python-version: ${{ matrix.python }}
|
||||||
- run: python -mpip install --upgrade setuptools pip tox virtualenv
|
- run: python -mpip install --upgrade setuptools pip tox virtualenv
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/asottile/add-trailing-comma
|
- repo: https://github.com/asottile/add-trailing-comma
|
||||||
rev: v3.2.0
|
rev: v4.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: add-trailing-comma
|
- id: add-trailing-comma
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
|
@ -12,23 +12,23 @@ repos:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
exclude: ^tests/fixtures/
|
exclude: ^tests/fixtures/
|
||||||
- repo: https://github.com/asottile/setup-cfg-fmt
|
- repo: https://github.com/asottile/setup-cfg-fmt
|
||||||
rev: v2.8.0
|
rev: v3.1.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: setup-cfg-fmt
|
- id: setup-cfg-fmt
|
||||||
- repo: https://github.com/asottile/reorder-python-imports
|
- repo: https://github.com/asottile/reorder-python-imports
|
||||||
rev: v3.15.0
|
rev: v3.16.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: reorder-python-imports
|
- id: reorder-python-imports
|
||||||
args: [
|
args: [
|
||||||
--application-directories, '.:src',
|
--application-directories, '.:src',
|
||||||
--py39-plus,
|
--py310-plus,
|
||||||
--add-import, 'from __future__ import annotations',
|
--add-import, 'from __future__ import annotations',
|
||||||
]
|
]
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
rev: v3.20.0
|
rev: v3.21.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
args: [--py39-plus]
|
args: [--py310-plus]
|
||||||
- repo: https://github.com/hhatto/autopep8
|
- repo: https://github.com/hhatto/autopep8
|
||||||
rev: v2.3.2
|
rev: v2.3.2
|
||||||
hooks:
|
hooks:
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ from __future__ import annotations
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import os.path
|
import os.path
|
||||||
|
from collections.abc import Callable
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Callable
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
import pycodestyle
|
import pycodestyle
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ install_requires =
|
||||||
mccabe>=0.7.0,<0.8.0
|
mccabe>=0.7.0,<0.8.0
|
||||||
pycodestyle>=2.14.0,<2.15.0
|
pycodestyle>=2.14.0,<2.15.0
|
||||||
pyflakes>=3.4.0,<3.5.0
|
pyflakes>=3.4.0,<3.5.0
|
||||||
python_requires = >=3.9
|
python_requires = >=3.10
|
||||||
package_dir =
|
package_dir =
|
||||||
=src
|
=src
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -372,43 +372,6 @@ class FileChecker:
|
||||||
token = ()
|
token = ()
|
||||||
row, column = (1, 0)
|
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
|
return row, column
|
||||||
|
|
||||||
def run_ast_checks(self) -> None:
|
def run_ast_checks(self) -> None:
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
|
from collections.abc import Callable
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from flake8 import utils
|
from flake8 import utils
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import argparse
|
||||||
import enum
|
import enum
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
|
from collections.abc import Callable
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from flake8 import utils
|
from flake8 import utils
|
||||||
from flake8.plugins.finder import Plugins
|
from flake8.plugins.finder import Plugins
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import importlib.metadata
|
import importlib.metadata
|
||||||
import sys
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -322,17 +321,10 @@ def test_handling_syntaxerrors_across_pythons():
|
||||||
We need to handle that correctly to avoid crashing.
|
We need to handle that correctly to avoid crashing.
|
||||||
https://github.com/PyCQA/flake8/issues/1372
|
https://github.com/PyCQA/flake8/issues/1372
|
||||||
"""
|
"""
|
||||||
if sys.version_info < (3, 10): # pragma: no cover (<3.10)
|
err = SyntaxError(
|
||||||
# Python 3.9 or older
|
"invalid syntax", ("<unknown>", 2, 1, "bad python:\n", 2, 11),
|
||||||
err = SyntaxError(
|
)
|
||||||
"invalid syntax", ("<unknown>", 2, 5, "bad python:\n"),
|
expected = (2, 1)
|
||||||
)
|
|
||||||
expected = (2, 4)
|
|
||||||
else: # pragma: no cover (3.10+)
|
|
||||||
err = SyntaxError(
|
|
||||||
"invalid syntax", ("<unknown>", 2, 1, "bad python:\n", 2, 11),
|
|
||||||
)
|
|
||||||
expected = (2, 1)
|
|
||||||
file_checker = checker.FileChecker(
|
file_checker = checker.FileChecker(
|
||||||
filename="-",
|
filename="-",
|
||||||
plugins=finder.Checkers([], [], []),
|
plugins=finder.Checkers([], [], []),
|
||||||
|
|
|
||||||
|
|
@ -168,10 +168,8 @@ def test_tokenization_error_but_not_syntax_error(tmpdir, capsys):
|
||||||
tmpdir.join("t.py").write("b'foo' \\\n")
|
tmpdir.join("t.py").write("b'foo' \\\n")
|
||||||
assert cli.main(["t.py"]) == 1
|
assert cli.main(["t.py"]) == 1
|
||||||
|
|
||||||
if hasattr(sys, "pypy_version_info"): # pragma: no cover (pypy)
|
if sys.implementation.name == "pypy": # pragma: no cover (pypy)
|
||||||
expected = "t.py:2:1: E999 SyntaxError: end of file (EOF) in multi-line statement\n" # noqa: E501
|
expected = "t.py:1:9: E999 SyntaxError: unexpected 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"
|
|
||||||
else: # pragma: no cover (cp310+)
|
else: # pragma: no cover (cp310+)
|
||||||
expected = "t.py:1:10: E999 SyntaxError: unexpected EOF while parsing\n" # noqa: E501
|
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")
|
tmpdir.join("t.py").write("if True:\n pass\n pass\n")
|
||||||
assert cli.main(["t.py"]) == 1
|
assert cli.main(["t.py"]) == 1
|
||||||
|
|
||||||
if hasattr(sys, "pypy_version_info"): # pragma: no cover (pypy)
|
if sys.implementation.name == "pypy": # pragma: no cover (pypy)
|
||||||
expected = "t.py:3:2: E999 IndentationError: unindent does not match any outer indentation level\n" # noqa: E501
|
expected = "t.py:3:3: 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
|
|
||||||
else: # pragma: no cover (cp310+)
|
else: # pragma: no cover (cp310+)
|
||||||
expected = "t.py:3:7: E999 IndentationError: unindent does not match any outer indentation level\n" # noqa: E501
|
expected = "t.py:3:7: E999 IndentationError: unindent does not match any outer indentation level\n" # noqa: E501
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue