Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: enable Ruff ARG rules
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Nov 12, 2025
commit 24bbe725e473bfe9cb384ba9e6dc8e1f544462b2
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
rev: v0.13.0
hooks:
- id: ruff-check
args: [ --fix, --show-fixes ]
args: [ --show-fixes ]
- id: ruff-format

- repo: https://github.com/pre-commit/pygrep-hooks
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ extend-exclude = [

[tool.ruff.lint]
extend-select = [
"ARG", # flake8-unused-argument
"B", # flake8-bugbear
"E",
"EXE", # flake8-executable
Expand Down Expand Up @@ -116,6 +117,7 @@ ignore = [
"PLW0127", # duplicate of F821
"TRY003", # long messages outside exception class
]
flake8-unused-arguments.ignore-variadic-names = true

[tool.ruff.lint.per-file-ignores]
"tests/test_*.py" = ["PYI024", "PLR"]
Expand Down
10 changes: 5 additions & 5 deletions tests/test_manylinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,20 @@ def __init__(self, libc_version):


def test_glibc_version_string_confstr(monkeypatch):
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False)
monkeypatch.setattr(os, "confstr", lambda _: "glibc 2.20", raising=False)
assert _glibc_version_string_confstr() == "2.20"


def test_glibc_version_string_fail(monkeypatch):
monkeypatch.setattr(os, "confstr", lambda x: None, raising=False)
monkeypatch.setattr(os, "confstr", lambda _: None, raising=False)
monkeypatch.setitem(sys.modules, "ctypes", None)
assert _glibc_version_string() is None
assert _get_glibc_version() == (-1, -1)


@pytest.mark.parametrize(
"failure",
[pretend.raiser(ValueError), pretend.raiser(OSError), lambda x: "XXX"],
[pretend.raiser(ValueError), pretend.raiser(OSError), lambda _: "XXX"],
)
def test_glibc_version_string_confstr_fail(monkeypatch, failure):
monkeypatch.setattr(os, "confstr", failure, raising=False)
Expand All @@ -141,7 +141,7 @@ def test_glibc_version_string_ctypes_missing(monkeypatch):

@pytest.mark.xfail(ctypes is None, reason="ctypes not available")
def test_glibc_version_string_ctypes_raise_oserror(monkeypatch):
def patched_cdll(name):
def patched_cdll(_name):
raise OSError("Dynamic loading not supported")

monkeypatch.setattr(ctypes, "CDLL", patched_cdll)
Expand All @@ -168,7 +168,7 @@ def test_glibc_version_string_none(monkeypatch):
@pytest.mark.parametrize(
"content", [None, "invalid-magic", "invalid-class", "invalid-data", "too-short"]
)
def test_parse_elf_bad_executable(monkeypatch, content):
def test_parse_elf_bad_executable(content):
if content:
path = pathlib.Path(__file__).parent / "manylinux" / f"hello-world-{content}"
path = os.fsdecode(path)
Expand Down
46 changes: 26 additions & 20 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class MockImplementation:
monkeypatch.setattr(sys, "implementation", mock_implementation, raising=False)
assert tags.interpreter_name() == "sillywalk"

def test_interpreter_short_names(self, mock_interpreter_name, monkeypatch):
def test_interpreter_short_names(self, mock_interpreter_name):
mock_interpreter_name("cpython")
assert tags.interpreter_name() == "cp"

Expand All @@ -180,7 +180,7 @@ def __init__(self, return_):
self.warn = None
self._return = return_

def __call__(self, name, warn):
def __call__(self, _name, warn):
self.warn = warn
return self._return

Expand All @@ -190,7 +190,7 @@ def __call__(self, name, warn):
assert mock_config_var.warn

def test_python_version_nodot(self, monkeypatch):
monkeypatch.setattr(tags, "_get_config_var", lambda var, warn: "NN")
monkeypatch.setattr(tags, "_get_config_var", lambda _var, warn: "NN") # noqa: ARG005
assert tags.interpreter_version() == "NN"

@pytest.mark.parametrize(
Expand Down Expand Up @@ -378,7 +378,8 @@ def test_macos_11(self, major, minor):


class TestIOSPlatforms:
def test_version_detection(self, mock_ios):
@pytest.mark.usefixtures("mock_ios")
def test_version_detection(self):
platforms = list(tags.ios_platforms(multiarch="arm64-iphoneos"))
assert platforms == [
"ios_13_2_arm64_iphoneos",
Expand All @@ -396,11 +397,13 @@ def test_version_detection(self, mock_ios):
"ios_12_0_arm64_iphoneos",
]

def test_multiarch_detection(self, mock_ios):
@pytest.mark.usefixtures("mock_ios")
def test_multiarch_detection(self):
platforms = list(tags.ios_platforms(version=(12, 0)))
assert platforms == ["ios_12_0_gothic_iphoneos"]

def test_ios_platforms(self, mock_ios):
@pytest.mark.usefixtures("mock_ios")
def test_ios_platforms(self):
# Pre-iOS 12.0 releases won't match anything
platforms = list(tags.ios_platforms((7, 0), "arm64-iphoneos"))
assert platforms == []
Expand Down Expand Up @@ -473,7 +476,8 @@ def test_non_android(self):
"android_16_x86_64",
]

def test_detection(self, mock_android):
@pytest.mark.usefixtures("mock_android")
def test_detection(self):
assert list(tags.android_platforms()) == [
"android_21_arm64_v8a",
"android_20_arm64_v8a",
Expand Down Expand Up @@ -553,7 +557,7 @@ def test_linux_platforms_32_64bit_on_64bit_os(
self, arch, is_32bit, expected, monkeypatch
):
monkeypatch.setattr(sysconfig, "get_platform", lambda: arch)
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False)
monkeypatch.setattr(os, "confstr", lambda _: "glibc 2.20", raising=False)
monkeypatch.setattr(tags._manylinux, "_is_compatible", lambda *args: False)
linux_platform = list(tags._linux_platforms(is_32bit=is_32bit))[
-len(expected) :
Expand All @@ -562,7 +566,7 @@ def test_linux_platforms_32_64bit_on_64bit_os(

def test_linux_platforms_manylinux_unsupported(self, monkeypatch):
monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64")
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False)
monkeypatch.setattr(os, "confstr", lambda _: "glibc 2.20", raising=False)
monkeypatch.setattr(tags._manylinux, "_is_compatible", lambda *args: False)
linux_platform = list(tags._linux_platforms(is_32bit=False))
assert linux_platform == ["linux_x86_64"]
Expand All @@ -575,7 +579,7 @@ def test_linux_platforms_manylinux1(self, monkeypatch):
)
monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64")
monkeypatch.setattr(platform, "machine", lambda: "x86_64")
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False)
monkeypatch.setattr(os, "confstr", lambda _: "glibc 2.20", raising=False)
platforms = list(tags._linux_platforms(is_32bit=False))
assert platforms == [
"manylinux_2_5_x86_64",
Expand All @@ -586,7 +590,7 @@ def test_linux_platforms_manylinux1(self, monkeypatch):
def test_linux_platforms_manylinux2010(self, monkeypatch):
monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64")
monkeypatch.setattr(platform, "machine", lambda: "x86_64")
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.12", raising=False)
monkeypatch.setattr(os, "confstr", lambda _: "glibc 2.12", raising=False)
platforms = list(tags._linux_platforms(is_32bit=False))
expected = [
"manylinux_2_12_x86_64",
Expand All @@ -606,7 +610,7 @@ def test_linux_platforms_manylinux2010(self, monkeypatch):
def test_linux_platforms_manylinux2014(self, monkeypatch):
monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64")
monkeypatch.setattr(platform, "machine", lambda: "x86_64")
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.17", raising=False)
monkeypatch.setattr(os, "confstr", lambda _: "glibc 2.17", raising=False)
platforms = list(tags._linux_platforms(is_32bit=False))
arch = platform.machine()
expected = [
Expand Down Expand Up @@ -763,7 +767,7 @@ def test_linux_platforms_manylinux2014_armv6l(self, monkeypatch):
lambda _, glibc_version: glibc_version == _GLibCVersion(2, 17),
)
monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_armv6l")
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False)
monkeypatch.setattr(os, "confstr", lambda _: "glibc 2.20", raising=False)
platforms = list(tags._linux_platforms(is_32bit=True))
expected = ["linux_armv6l"]
assert platforms == expected
Expand Down Expand Up @@ -793,7 +797,7 @@ def test_linux_platforms_not_manylinux_abi(
def test_linux_not_linux(self, monkeypatch):
monkeypatch.setattr(sysconfig, "get_platform", lambda: "not_linux_x86_64")
monkeypatch.setattr(platform, "machine", lambda: "x86_64")
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.17", raising=False)
monkeypatch.setattr(os, "confstr", lambda _: "glibc 2.17", raising=False)
platforms = list(tags._linux_platforms(is_32bit=False))
assert platforms == ["not_linux_x86_64"]

Expand Down Expand Up @@ -1058,7 +1062,7 @@ def test_no_abi3_python27(self):
class TestGenericTags:
def test__generic_abi_macos(self, monkeypatch):
monkeypatch.setattr(
sysconfig, "get_config_var", lambda key: ".cpython-37m-darwin.so"
sysconfig, "get_config_var", lambda _: ".cpython-37m-darwin.so"
)
monkeypatch.setattr(tags, "interpreter_name", lambda: "cp")
assert tags._generic_abi() == ["cp37m"]
Expand Down Expand Up @@ -1176,7 +1180,7 @@ def test_abi_unspecified(self, abi):

def test_interpreter_default(self, monkeypatch):
monkeypatch.setattr(tags, "interpreter_name", lambda: "sillywalk")
monkeypatch.setattr(tags, "interpreter_version", lambda warn: "NN")
monkeypatch.setattr(tags, "interpreter_version", lambda warn: "NN") # noqa: ARG005
result = list(tags.generic_tags(abis=["none"], platforms=["any"]))
assert result == [tags.Tag("sillywalkNN", "none", "any")]

Expand Down Expand Up @@ -1421,9 +1425,10 @@ def test_generic(self, monkeypatch):
)
assert result[-1] == expected

def test_linux_platforms_manylinux2014_armv6l(self, monkeypatch, manylinux_module):
@pytest.mark.usefixtures("manylinux_module")
def test_linux_platforms_manylinux2014_armv6l(self, monkeypatch):
monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_armv6l")
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False)
monkeypatch.setattr(os, "confstr", lambda _: "glibc 2.20", raising=False)
platforms = list(tags._linux_platforms(is_32bit=True))
expected = ["linux_armv6l"]
assert platforms == expected
Expand All @@ -1445,12 +1450,13 @@ def test_skip_manylinux_2014(self, monkeypatch, manylinux_module):
platforms = list(tags._linux_platforms())
assert platforms == expected

@pytest.mark.usefixtures("manylinux_module")
@pytest.mark.parametrize(
"machine, abi, alt_machine",
[("x86_64", "x32", "i686"), ("armv7l", "armel", "armv7l")],
)
def test_linux_platforms_not_manylinux_abi(
self, monkeypatch, manylinux_module, machine, abi, alt_machine
self, monkeypatch, machine, abi, alt_machine
):
monkeypatch.setattr(sysconfig, "get_platform", lambda: f"linux_{machine}")
monkeypatch.setattr(
Expand Down Expand Up @@ -1498,7 +1504,7 @@ def manylinux_compatible(tag_major, tag_minor, tag_arch):
assert platforms == expected

def test_linux_use_manylinux_compatible_none(self, monkeypatch, manylinux_module):
def manylinux_compatible(tag_major, tag_minor, tag_arch):
def manylinux_compatible(tag_major, tag_minor, tag_arch): # noqa: ARG001
if tag_major == 2 and tag_minor < 25:
return False
return None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def test_dunder_op_returns_notimplemented(self, op):

@pytest.mark.parametrize(("op", "expected"), [("eq", False), ("ne", True)])
def test_compare_other(self, op, expected):
other = pretend.stub(**{f"__{op}__": lambda other: NotImplemented})
other = pretend.stub(**{f"__{op}__": lambda _: NotImplemented})

assert getattr(operator, op)(Version("1"), other) is expected

Expand Down