Skip to content

Commit b8f8bcc

Browse files
authored
Merge pull request #4386 from DimitriPapadopoulos/FURB
Enforce ruff/refurb rules (FURB)
2 parents d126744 + be06d67 commit b8f8bcc

File tree

15 files changed

+36
-27
lines changed

15 files changed

+36
-27
lines changed

pkg_resources/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ class _ZipLoaderModule(Protocol):
131131
__loader__: zipimport.zipimporter
132132

133133

134-
_PEP440_FALLBACK = re.compile(r"^v?(?P<safe>(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.I)
134+
_PEP440_FALLBACK = re.compile(
135+
r"^v?(?P<safe>(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.IGNORECASE
136+
)
135137

136138

137139
class PEP440Warning(RuntimeWarning):

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extend-select = [
2727
# local
2828
"ANN2", # missing-return-type-*
2929
"ISC", # flake8-implicit-str-concat
30+
"FURB", # refurb
3031
"PERF", # Perflint
3132
"PGH", # pygrep-hooks (blanket-* rules)
3233
"PT", # flake8-pytest-style

setuptools/_normalization.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import packaging
1010

1111
# https://packaging.python.org/en/latest/specifications/core-metadata/#name
12-
_VALID_NAME = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.I)
13-
_UNSAFE_NAME_CHARS = re.compile(r"[^A-Z0-9._-]+", re.I)
14-
_NON_ALPHANUMERIC = re.compile(r"[^A-Z0-9]+", re.I)
15-
_PEP440_FALLBACK = re.compile(r"^v?(?P<safe>(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.I)
12+
_VALID_NAME = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.IGNORECASE)
13+
_UNSAFE_NAME_CHARS = re.compile(r"[^A-Z0-9._-]+", re.IGNORECASE)
14+
_NON_ALPHANUMERIC = re.compile(r"[^A-Z0-9]+", re.IGNORECASE)
15+
_PEP440_FALLBACK = re.compile(
16+
r"^v?(?P<safe>(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.IGNORECASE
17+
)
1618

1719

1820
def safe_identifier(name: str) -> str:

setuptools/command/bdist_egg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def _get_purelib():
3737
def strip_module(filename):
3838
if '.' in filename:
3939
filename = os.path.splitext(filename)[0]
40-
if filename.endswith('module'):
41-
filename = filename[:-6]
40+
filename = filename.removesuffix('module')
4241
return filename
4342

4443

setuptools/command/build_ext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import itertools
4+
import operator
45
import os
56
import sys
67
import textwrap
@@ -323,7 +324,7 @@ def get_outputs(self) -> list[str]:
323324
def get_output_mapping(self) -> dict[str, str]:
324325
"""See :class:`setuptools.commands.build.SubCommand`"""
325326
mapping = self._get_output_mapping()
326-
return dict(sorted(mapping, key=lambda x: x[0]))
327+
return dict(sorted(mapping, key=operator.itemgetter(0)))
327328

328329
def __get_stubs_outputs(self):
329330
# assemble the base name for each extension that needs a stub

setuptools/command/build_py.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import fnmatch
44
import itertools
5+
import operator
56
import os
67
import stat
78
import textwrap
@@ -149,7 +150,7 @@ def get_output_mapping(self) -> dict[str, str]:
149150
self._get_package_data_output_mapping(),
150151
self._get_module_mapping(),
151152
)
152-
return dict(sorted(mapping, key=lambda x: x[0]))
153+
return dict(sorted(mapping, key=operator.itemgetter(0)))
153154

154155
def _get_module_mapping(self) -> Iterator[tuple[str, str]]:
155156
"""Iterate over all modules producing (dest, src) pairs."""

setuptools/command/editable_wheel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import io
1616
import logging
17+
import operator
1718
import os
1819
import shutil
1920
import traceback
@@ -665,7 +666,7 @@ def _parent_path(pkg, pkg_path):
665666
>>> _parent_path("b", "src/c")
666667
'src/c'
667668
"""
668-
parent = pkg_path[: -len(pkg)] if pkg_path.endswith(pkg) else pkg_path
669+
parent = pkg_path.removesuffix(pkg)
669670
return parent.rstrip("/" + os.sep)
670671

671672

@@ -906,7 +907,7 @@ def _finder_template(
906907
"""Create a string containing the code for the``MetaPathFinder`` and
907908
``PathEntryFinder``.
908909
"""
909-
mapping = dict(sorted(mapping.items(), key=lambda p: p[0]))
910+
mapping = dict(sorted(mapping.items(), key=operator.itemgetter(0)))
910911
return _FINDER_TEMPLATE.format(name=name, mapping=mapping, namespaces=namespaces)
911912

912913

setuptools/command/egg_info.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ def global_exclude(self, pattern):
477477
return self._remove_files(match.match)
478478

479479
def append(self, item) -> None:
480-
if item.endswith('\r'): # Fix older sdists built on Windows
481-
item = item[:-1]
480+
item = item.removesuffix('\r') # Fix older sdists built on Windows
482481
path = convert_path(item)
483482

484483
if self._safe_path(path):

setuptools/dist.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,7 @@ def iter_distribution_names(self) -> Iterator[str]:
10681068
name, _buildinfo = ext
10691069
else:
10701070
name = ext.name
1071-
if name.endswith('module'):
1072-
name = name[:-6]
1071+
name = name.removesuffix('module')
10731072
yield name
10741073

10751074
def handle_display_options(self, option_order):

setuptools/msvc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def _find_latest_available_vs_ver(self):
402402

403403
vc_vers = set(reg_vc_vers)
404404
vc_vers.update(self.known_vs_paths)
405-
return sorted(vc_vers)[-1]
405+
return max(vc_vers)
406406

407407
def find_reg_vs_vers(self) -> list[float]:
408408
"""

0 commit comments

Comments
 (0)