diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4881b413ec..e48fbfd956 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -66,10 +66,10 @@ repos: - id: fix-smartquotes - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.238 + rev: v0.0.247 hooks: - id: ruff - args: ["--fix"] + args: ["--fix", "--show-fixes"] # Checking for common mistakes - repo: https://github.com/pre-commit/pygrep-hooks diff --git a/pybind11/__init__.py b/pybind11/__init__.py index 4fbb17079f..7c10b30578 100644 --- a/pybind11/__init__.py +++ b/pybind11/__init__.py @@ -1,6 +1,6 @@ import sys -if sys.version_info < (3, 6): +if sys.version_info < (3, 6): # noqa: UP036 msg = "pybind11 does not support Python < 3.6. 2.9 was the last release supporting Python 2.7 and 3.5." raise ImportError(msg) diff --git a/pyproject.toml b/pyproject.toml index 87ef55277b..a087f285b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,10 +76,11 @@ select = [ "YTT", # flake8-2020 ] ignore = [ - "PLR2004", "PLR0913", + "PLR", # Design related pylint "E501", # Line too long (Black is enough) "PT011", # Too broad with raises in pytest "PT004", # Fixture that doesn't return needs underscore (no, it is fine) + "SIM118",# iter(x) is not always the same as iter(x.keys()) ] target-version = "py37" typing-modules = ["scikit_build_core._compat.typing"] diff --git a/tests/test_const_name.py b/tests/test_const_name.py index 885a07c0f4..a145f0bbb5 100644 --- a/tests/test_const_name.py +++ b/tests/test_const_name.py @@ -5,7 +5,7 @@ @pytest.mark.parametrize("func", [m.const_name_tests, m.underscore_tests]) @pytest.mark.parametrize( - "selector, expected", + ("selector", "expected"), enumerate( ( "", diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index edbdea9c8b..7f80a5da56 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -341,10 +341,7 @@ def test_flaky_exception_failure_point_str(): ) assert not py_err_set_after_what lines = what.splitlines() - if env.PYPY and len(lines) == 3: - n = 3 # Traceback is missing. - else: - n = 5 + n = 3 if env.PYPY and len(lines) == 3 else 5 assert ( lines[:n] == [ diff --git a/tests/test_modules.py b/tests/test_modules.py index c3e8cea6e1..3d73e3fbd2 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -1,3 +1,5 @@ +import builtins + import pytest import env @@ -86,12 +88,7 @@ def test_builtin_key_type(): Previous versions of pybind11 would add a unicode key in python 2. """ - if hasattr(__builtins__, "keys"): - keys = __builtins__.keys() - else: # this is to make pypy happy since builtins is different there. - keys = __builtins__.__dict__.keys() - - assert {type(k) for k in keys} == {str} + assert all(type(k) == str for k in dir(builtins)) @pytest.mark.xfail("env.PYPY", reason="PyModule_GetName()") diff --git a/tests/test_sequences_and_iterators.py b/tests/test_sequences_and_iterators.py index e0d98538a9..dc129f2bff 100644 --- a/tests/test_sequences_and_iterators.py +++ b/tests/test_sequences_and_iterators.py @@ -72,13 +72,13 @@ def test_iterator_referencing(): vec = m.VectorNonCopyableIntPair() vec.append([3, 4]) vec.append([5, 7]) - assert [int(x) for x in vec] == [3, 5] + assert [int(x) for x in vec.keys()] == [3, 5] assert [int(x) for x in vec.values()] == [4, 7] - for x in vec: + for x in vec.keys(): x.set(int(x) + 1) for x in vec.values(): x.set(int(x) + 10) - assert [int(x) for x in vec] == [4, 6] + assert [int(x) for x in vec.keys()] == [4, 6] assert [int(x) for x in vec.values()] == [14, 17]