Skip to content

Commit 2c885fe

Browse files
Apply ruff/pyupgrade rules (UP) (#786)
* Apply ruff/pyupgrade issue UP030 UP030 Use implicit references for positional format fields * Apply ruff/pyupgrade rule UP031 UP031 Use format specifiers instead of percent format * Apply ruff/pyupgrade rule UP032 UP032 Use f-string instead of `format` call
1 parent 6c5698a commit 2c885fe

File tree

6 files changed

+24
-34
lines changed

6 files changed

+24
-34
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ ignore = [
7878
"N818",
7979
"RUF003",
8080
"RUF012",
81-
"UP030",
8281
"UP032",
8382
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
8483
"W191",

src/packaging/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
__email__ = "[email protected]"
1313

1414
__license__ = "BSD-2-Clause or Apache-2.0"
15-
__copyright__ = "2014 %s" % __author__
15+
__copyright__ = f"2014 {__author__}"

src/packaging/markers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _evaluate_markers(markers: MarkerList, environment: dict[str, str]) -> bool:
232232

233233

234234
def format_full_version(info: sys._version_info) -> str:
235-
version = "{0.major}.{0.minor}.{0.micro}".format(info)
235+
version = f"{info.major}.{info.minor}.{info.micro}"
236236
kind = info.releaselevel
237237
if kind != "final":
238238
version += kind[0] + str(info.serial)

src/packaging/tags.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,8 @@ def cpython_tags(
235235
if use_abi3:
236236
for minor_version in range(python_version[1] - 1, 1, -1):
237237
for platform_ in platforms:
238-
interpreter = "cp{version}".format(
239-
version=_version_nodot((python_version[0], minor_version))
240-
)
238+
version = _version_nodot((python_version[0], minor_version))
239+
interpreter = f"cp{version}"
241240
yield Tag(interpreter, "abi3", platform_)
242241

243242

@@ -435,24 +434,22 @@ def mac_platforms(
435434
if (10, 0) <= version and version < (11, 0):
436435
# Prior to Mac OS 11, each yearly release of Mac OS bumped the
437436
# "minor" version number. The major version was always 10.
437+
major_version = 10
438438
for minor_version in range(version[1], -1, -1):
439-
compat_version = 10, minor_version
439+
compat_version = major_version, minor_version
440440
binary_formats = _mac_binary_formats(compat_version, arch)
441441
for binary_format in binary_formats:
442-
yield "macosx_{major}_{minor}_{binary_format}".format(
443-
major=10, minor=minor_version, binary_format=binary_format
444-
)
442+
yield f"macosx_{major_version}_{minor_version}_{binary_format}"
445443

446444
if version >= (11, 0):
447445
# Starting with Mac OS 11, each yearly release bumps the major version
448446
# number. The minor versions are now the midyear updates.
447+
minor_version = 0
449448
for major_version in range(version[0], 10, -1):
450-
compat_version = major_version, 0
449+
compat_version = major_version, minor_version
451450
binary_formats = _mac_binary_formats(compat_version, arch)
452451
for binary_format in binary_formats:
453-
yield "macosx_{major}_{minor}_{binary_format}".format(
454-
major=major_version, minor=0, binary_format=binary_format
455-
)
452+
yield f"macosx_{major_version}_{minor_version}_{binary_format}"
456453

457454
if version >= (11, 0):
458455
# Mac OS 11 on x86_64 is compatible with binaries from previous releases.
@@ -462,25 +459,18 @@ def mac_platforms(
462459
# However, the "universal2" binary format can have a
463460
# macOS version earlier than 11.0 when the x86_64 part of the binary supports
464461
# that version of macOS.
462+
major_version = 10
465463
if arch == "x86_64":
466464
for minor_version in range(16, 3, -1):
467-
compat_version = 10, minor_version
465+
compat_version = major_version, minor_version
468466
binary_formats = _mac_binary_formats(compat_version, arch)
469467
for binary_format in binary_formats:
470-
yield "macosx_{major}_{minor}_{binary_format}".format(
471-
major=compat_version[0],
472-
minor=compat_version[1],
473-
binary_format=binary_format,
474-
)
468+
yield f"macosx_{major_version}_{minor_version}_{binary_format}"
475469
else:
476470
for minor_version in range(16, 3, -1):
477-
compat_version = 10, minor_version
471+
compat_version = major_version, minor_version
478472
binary_format = "universal2"
479-
yield "macosx_{major}_{minor}_{binary_format}".format(
480-
major=compat_version[0],
481-
minor=compat_version[1],
482-
binary_format=binary_format,
483-
)
473+
yield f"macosx_{major_version}_{minor_version}_{binary_format}"
484474

485475

486476
def _linux_platforms(is_32bit: bool = _32_BIT_INTERPRETER) -> Iterator[str]:

tests/test_markers.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,15 @@ class TestDefaultEnvironment:
103103
def test_matches_expected(self):
104104
environment = default_environment()
105105

106-
iver = "{0.major}.{0.minor}.{0.micro}".format(sys.implementation.version)
106+
iver = (
107+
f"{sys.implementation.version.major}."
108+
f"{sys.implementation.version.minor}."
109+
f"{sys.implementation.version.micro}"
110+
)
107111
if sys.implementation.version.releaselevel != "final":
108-
iver = "{0}{1[0]}{2}".format(
109-
iver,
110-
sys.implementation.version.releaselevel,
111-
sys.implementation.version.serial,
112+
iver = (
113+
f"{iver}{sys.implementation.version.releaselevel[0]}"
114+
f"{sys.implementation.version.serial}"
112115
)
113116

114117
assert environment == {

tests/test_tags.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ def test_str(self, example_tag):
8080
assert str(example_tag) == "py3-none-any"
8181

8282
def test_repr(self, example_tag):
83-
assert repr(example_tag) == "<py3-none-any @ {tag_id}>".format(
84-
tag_id=id(example_tag)
85-
)
83+
assert repr(example_tag) == f"<py3-none-any @ {id(example_tag)}>"
8684

8785
def test_attribute_access(self, example_tag):
8886
assert example_tag.interpreter == "py3"

0 commit comments

Comments
 (0)