Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff (#11911)

ruff is faster and handle everything we had prior.

isort configuration done based on the indication from
https://github.com/astral-sh/ruff/issues/4670, previousely based on
reorder-python-import (#11896)

flake8-docstrings was a wrapper around pydocstyle (now archived) that
explicitly asks to use ruff in https://github.com/PyCQA/pydocstyle/pull/658.

flake8-typing-import is useful mainly for project that support python 3.7
and the one useful check will be implemented in https://github.com/astral-sh/ruff/issues/2302

We need to keep blacken-doc because ruff does not handle detection
of python code inside .md and .rst. The direct link to the repo is
now used to avoid a redirection.

Manual fixes:
- Lines that became too long
- % formatting that was not done automatically
- type: ignore that were moved around
- noqa of hard to fix issues (UP031 generally)
- fmt: off and fmt: on that is not really identical
  between black and ruff
- autofix re-order in pre-commit from faster to slower

Co-authored-by: Ran Benita <ran@unusedvar.com>
This commit is contained in:
Pierre Sassoulas
2024-02-02 20:21:46 +01:00
committed by GitHub
parent 368cc6225e
commit c11cdfabd1
151 changed files with 789 additions and 955 deletions

View File

@@ -1,17 +1,18 @@
import operator
from contextlib import contextmanager
from decimal import Decimal
from fractions import Fraction
from math import sqrt
import operator
from operator import eq
from operator import ne
from typing import Optional
import pytest
from _pytest.pytester import Pytester
from _pytest.python_api import _recursive_sequence_map
import pytest
from pytest import approx
inf, nan = float("inf"), float("nan")
@@ -37,9 +38,7 @@ def mocked_doctest_runner(monkeypatch):
class MyDocTestRunner(doctest.DocTestRunner):
def report_failure(self, out, test, example, got):
raise AssertionError(
"'{}' evaluates to '{}', not '{}'".format(
example.source.strip(), got.strip(), example.want.strip()
)
f"'{example.source.strip()}' evaluates to '{got.strip()}', not '{example.want.strip()}'"
)
return MyDocTestRunner()

View File

@@ -5,7 +5,6 @@ from typing import Any
from typing import Dict
import _pytest._code
import pytest
from _pytest.config import ExitCode
from _pytest.main import Session
from _pytest.monkeypatch import MonkeyPatch
@@ -13,6 +12,7 @@ from _pytest.nodes import Collector
from _pytest.pytester import Pytester
from _pytest.python import Class
from _pytest.python import Function
import pytest
class TestModule:
@@ -53,13 +53,11 @@ class TestModule:
monkeypatch.syspath_prepend(str(root1))
p.write_text(
textwrap.dedent(
"""\
f"""\
import x456
def test():
assert x456.__file__.startswith({!r})
""".format(
str(root2)
)
assert x456.__file__.startswith({str(root2)!r})
"""
),
encoding="utf-8",
)

View File

@@ -1,9 +1,8 @@
import os
from pathlib import Path
import sys
import textwrap
from pathlib import Path
import pytest
from _pytest.compat import getfuncargnames
from _pytest.config import ExitCode
from _pytest.fixtures import deduplicate_names
@@ -12,6 +11,7 @@ from _pytest.monkeypatch import MonkeyPatch
from _pytest.pytester import get_public_names
from _pytest.pytester import Pytester
from _pytest.python import Function
import pytest
def test_getfuncargnames_functions():
@@ -1287,7 +1287,7 @@ class TestFixtureUsages:
@pytest.mark.parametrize("scope", ["function", "session"])
def test_parameters_without_eq_semantics(self, scope, pytester: Pytester) -> None:
pytester.makepyfile(
"""
f"""
class NoEq1: # fails on `a == b` statement
def __eq__(self, _):
raise RuntimeError
@@ -1309,9 +1309,7 @@ class TestFixtureUsages:
def test2(no_eq):
pass
""".format(
scope=scope
)
"""
)
result = pytester.runpytest()
result.stdout.fnmatch_lines(["*4 passed*"])
@@ -2198,7 +2196,7 @@ class TestAutouseManagement:
pass
def test_check():
assert values == ["new1", "new2", "fin2", "fin1"]
"""
""" # noqa: UP031 (python syntax issues)
% locals()
)
reprec = pytester.inline_run("-s")
@@ -3086,8 +3084,8 @@ class TestFixtureMarker:
pass
def test_other():
pass
"""
% {"scope": scope}
""" # noqa: UP031 (python syntax issues)
% {"scope": scope} # noqa: UP031 (python syntax issues)
)
reprec = pytester.inline_run("-lvs")
reprec.assertoutcome(passed=3)
@@ -3286,7 +3284,7 @@ class TestRequestScopeAccess:
assert request.config
def test_func():
pass
"""
""" # noqa: UP031 (python syntax issues)
% (scope, ok.split(), error.split())
)
reprec = pytester.inline_run("-l")
@@ -3307,7 +3305,7 @@ class TestRequestScopeAccess:
assert request.config
def test_func(arg):
pass
"""
""" # noqa: UP031 (python syntax issues)
% (scope, ok.split(), error.split())
)
reprec = pytester.inline_run()

View File

@@ -1,8 +1,8 @@
import pytest
from _pytest._code import getfslineno
from _pytest.fixtures import getfixturemarker
from _pytest.pytester import Pytester
from _pytest.python import Function
import pytest
def test_wrapped_getfslineno() -> None:

View File

@@ -13,7 +13,6 @@ from typing import Sequence
from typing import Tuple
from typing import Union
import pytest
from _pytest import fixtures
from _pytest import python
from _pytest.compat import getfuncargnames
@@ -23,6 +22,8 @@ from _pytest.pytester import Pytester
from _pytest.python import Function
from _pytest.python import IdMaker
from _pytest.scope import Scope
import pytest
# import hypothesis
# from hypothesis import strategies
@@ -1940,7 +1941,7 @@ class TestMarkersWithParametrization:
@pytest.mark.parametrize("strict", [True, False])
def test_xfail_passing_is_xpass(self, pytester: Pytester, strict: bool) -> None:
s = """
s = f"""
import pytest
m = pytest.mark.xfail("sys.version_info > (0, 0, 0)", reason="some bug", strict={strict})
@@ -1952,9 +1953,7 @@ class TestMarkersWithParametrization:
])
def test_increment(n, expected):
assert n + 1 == expected
""".format(
strict=strict
)
"""
pytester.makepyfile(s)
reprec = pytester.inline_run()
passed, failed = (2, 1) if strict else (3, 0)
@@ -2005,7 +2004,7 @@ class TestMarkersWithParametrization:
@pytest.mark.parametrize("strict", [True, False])
def test_parametrize_marked_value(self, pytester: Pytester, strict: bool) -> None:
s = """
s = f"""
import pytest
@pytest.mark.parametrize(("n", "expected"), [
@@ -2020,9 +2019,7 @@ class TestMarkersWithParametrization:
])
def test_increment(n, expected):
assert n + 1 == expected
""".format(
strict=strict
)
"""
pytester.makepyfile(s)
reprec = pytester.inline_run()
passed, failed = (0, 2) if strict else (2, 0)

View File

@@ -1,9 +1,9 @@
import re
import sys
import pytest
from _pytest.outcomes import Failed
from _pytest.pytester import Pytester
import pytest
class TestRaises: