Skip to content

Commit d3048fc

Browse files
committed
Apply more assorted Pyugrade suggestions (#4125)
2 parents e50a9f2 + 07774d9 commit d3048fc

19 files changed

+86
-81
lines changed

pkg_resources/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,7 @@ def _extract_resource(self, manager, zip_path): # noqa: C901
18951895
try:
18961896
rename(tmpnam, real_path)
18971897

1898-
except os.error:
1898+
except OSError:
18991899
if os.path.isfile(real_path):
19001900
if self._is_current(real_path, zip_path):
19011901
# the file became current since it was checked above,
@@ -1908,7 +1908,7 @@ def _extract_resource(self, manager, zip_path): # noqa: C901
19081908
return real_path
19091909
raise
19101910

1911-
except os.error:
1911+
except OSError:
19121912
# report a user-friendly error
19131913
manager.extraction_error()
19141914

@@ -2901,7 +2901,7 @@ def __getattr__(self, attr):
29012901

29022902
def __dir__(self):
29032903
return list(
2904-
set(super(Distribution, self).__dir__())
2904+
set(super().__dir__())
29052905
| set(attr for attr in self._provider.__dir__() if not attr.startswith('_'))
29062906
)
29072907

@@ -3168,7 +3168,7 @@ class RequirementParseError(packaging.requirements.InvalidRequirement):
31683168
class Requirement(packaging.requirements.Requirement):
31693169
def __init__(self, requirement_string):
31703170
"""DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
3171-
super(Requirement, self).__init__(requirement_string)
3171+
super().__init__(requirement_string)
31723172
self.unsafe_name = self.name
31733173
project_name = safe_name(self.name)
31743174
self.project_name, self.key = project_name, project_name.lower()

pkg_resources/tests/test_working_set.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def parametrize_test_working_set_resolve(*test_list):
7676
requirements,
7777
expected1,
7878
expected2,
79-
) = [
79+
) = (
8080
strip_comments(s.lstrip())
8181
for s in textwrap.dedent(test).lstrip().split('\n\n', 5)
82-
]
82+
)
8383
installed_dists = list(parse_distributions(installed_dists))
8484
installable_dists = list(parse_distributions(installable_dists))
8585
requirements = list(pkg_resources.parse_requirements(requirements))

ruff.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,27 @@ ignore = [
1616
"ISC001",
1717
"ISC002",
1818
]
19+
extend-select = [
20+
"UP", # pyupgrade
21+
]
22+
extend-ignore = [
23+
"UP015", # redundant-open-modes, explicit is prefered
24+
"UP030", # temporarily disabled
25+
"UP031", # temporarily disabled
26+
"UP032", # temporarily disabled
27+
"UP036", # temporarily disabled
28+
]
29+
extend-exclude = [
30+
"**/_vendor",
31+
"setuptools/_distutils",
32+
"setuptools/config/_validate_pyproject",
33+
]
1934

2035
[format]
36+
extend-exclude = [
37+
"**/_vendor",
38+
"setuptools/_distutils",
39+
"setuptools/config/_validate_pyproject",
40+
]
2141
# https://docs.astral.sh/ruff/settings/#format-quote-style
2242
quote-style = "preserve"

setuptools/build_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def run_setup(self, setup_script='setup.py'):
477477
sys.argv[0] = setup_script
478478

479479
try:
480-
super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
480+
super().run_setup(setup_script=setup_script)
481481
finally:
482482
# While PEP 517 frontends should be calling each hook in a fresh
483483
# subprocess according to the standard (and thus it should not be

setuptools/command/bdist_egg.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ def walk_egg(egg_dir):
321321
if 'EGG-INFO' in dirs:
322322
dirs.remove('EGG-INFO')
323323
yield base, dirs, files
324-
for bdf in walker:
325-
yield bdf
324+
yield from walker
326325

327326

328327
def analyze_egg(egg_dir, stubs):
@@ -406,14 +405,12 @@ def scan_module(egg_dir, base, name, stubs):
406405

407406
def iter_symbols(code):
408407
"""Yield names and strings used by `code` and its nested code objects"""
409-
for name in code.co_names:
410-
yield name
408+
yield from code.co_names
411409
for const in code.co_consts:
412410
if isinstance(const, str):
413411
yield const
414412
elif isinstance(const, CodeType):
415-
for name in iter_symbols(const):
416-
yield name
413+
yield from iter_symbols(const)
417414

418415

419416
def can_scan():

setuptools/command/easy_install.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,8 +1743,7 @@ class RewritePthDistributions(PthDistributions):
17431743
@classmethod
17441744
def _wrap_lines(cls, lines):
17451745
yield cls.prelude
1746-
for line in lines:
1747-
yield line
1746+
yield from lines
17481747
yield cls.postlude
17491748

17501749
prelude = _one_liner(
@@ -2024,7 +2023,7 @@ def chmod(path, mode):
20242023
log.debug("changing mode of %s to %o", path, mode)
20252024
try:
20262025
_chmod(path, mode)
2027-
except os.error as e:
2026+
except OSError as e:
20282027
log.debug("chmod failed: %s", e)
20292028

20302029

@@ -2180,8 +2179,7 @@ def get_args(cls, dist, header=None):
21802179
cls._ensure_safe_name(name)
21812180
script_text = cls.template % locals()
21822181
args = cls._get_script_args(type_, name, header, script_text)
2183-
for res in args:
2184-
yield res
2182+
yield from args
21852183

21862184
@staticmethod
21872185
def _ensure_safe_name(name):

setuptools/command/editable_wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def __init__(self, dist: Distribution, name: str, path_entries: List[Path]):
400400
self.path_entries = path_entries
401401

402402
def __call__(self, wheel: "WheelFile", files: List[str], mapping: Dict[str, str]):
403-
entries = "\n".join((str(p.resolve()) for p in self.path_entries))
403+
entries = "\n".join(str(p.resolve()) for p in self.path_entries)
404404
contents = _encode_pth(f"{entries}\n")
405405
wheel.writestr(f"__editable__.{self.name}.pth", contents)
406406

setuptools/command/sdist.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
def walk_revctrl(dirname=''):
1515
"""Find all files under revision control"""
1616
for ep in metadata.entry_points(group='setuptools.file_finders'):
17-
for item in ep.load()(dirname):
18-
yield item
17+
yield from ep.load()(dirname)
1918

2019

2120
class sdist(orig.sdist):
@@ -190,7 +189,7 @@ def _manifest_is_not_generated(self):
190189

191190
with open(self.manifest, 'rb') as fp:
192191
first_line = fp.readline()
193-
return first_line != '# file GENERATED by distutils, do NOT edit\n'.encode()
192+
return first_line != b'# file GENERATED by distutils, do NOT edit\n'
194193

195194
def read_manifest(self):
196195
"""Read the manifest file (named by 'self.manifest') and use it to

setuptools/dist.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,9 @@ def get_cmdline_options(self):
912912
def iter_distribution_names(self):
913913
"""Yield all packages, modules, and extension names in distribution"""
914914

915-
for pkg in self.packages or ():
916-
yield pkg
915+
yield from self.packages or ()
917916

918-
for module in self.py_modules or ():
919-
yield module
917+
yield from self.py_modules or ()
920918

921919
for ext in self.ext_modules or ():
922920
if isinstance(ext, tuple):

setuptools/glob.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ def glob0(dirname, basename):
113113
def glob2(dirname, pattern):
114114
assert _isrecursive(pattern)
115115
yield pattern[:0]
116-
for x in _rlistdir(dirname):
117-
yield x
116+
yield from _rlistdir(dirname)
118117

119118

120119
# Recursively yields relative pathnames inside a literal directory.
@@ -126,7 +125,7 @@ def _rlistdir(dirname):
126125
dirname = os.curdir
127126
try:
128127
names = os.listdir(dirname)
129-
except os.error:
128+
except OSError:
130129
return
131130
for x in names:
132131
yield x

0 commit comments

Comments
 (0)