Skip to content

Commit 11bd24c

Browse files
authored
Use set instead of True-only dict for non-public names (#4381)
2 parents 2adbd4f + f7c295a commit 11bd24c

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

pkg_resources/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -724,15 +724,15 @@ def __iter__(self) -> Iterator[Distribution]:
724724
The yield order is the order in which the items' path entries were
725725
added to the working set.
726726
"""
727-
seen = {}
727+
seen = set()
728728
for item in self.entries:
729729
if item not in self.entry_keys:
730730
# workaround a cache issue
731731
continue
732732

733733
for key in self.entry_keys[item]:
734734
if key not in seen:
735-
seen[key] = True
735+
seen.add(key)
736736
yield self.by_key[key]
737737

738738
def add(
@@ -808,7 +808,7 @@ def resolve(
808808
# set up the stack
809809
requirements = list(requirements)[::-1]
810810
# set of processed requirements
811-
processed = {}
811+
processed = set()
812812
# key -> dist
813813
best = {}
814814
to_activate = []
@@ -842,7 +842,7 @@ def resolve(
842842
required_by[new_requirement].add(req.project_name)
843843
req_extras[new_requirement] = req.extras
844844

845-
processed[req] = True
845+
processed.add(req)
846846

847847
# return list of distros to activate
848848
return to_activate
@@ -1313,7 +1313,7 @@ def get_cache_path(self, archive_name: str, names: Iterable[StrPath] = ()):
13131313

13141314
self._warn_unsafe_extraction_path(extract_path)
13151315

1316-
self.cached_files[target_path] = 1
1316+
self.cached_files[target_path] = True
13171317
return target_path
13181318

13191319
@staticmethod

setuptools/command/easy_install.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ def exe_to_egg(self, dist_filename, egg_tmp): # noqa: C901
10471047
prefixes = get_exe_prefixes(dist_filename)
10481048
to_compile = []
10491049
native_libs = []
1050-
top_level = {}
1050+
top_level = set()
10511051

10521052
def process(src, dst):
10531053
s = src.lower()
@@ -1059,10 +1059,10 @@ def process(src, dst):
10591059
dl = dst.lower()
10601060
if dl.endswith('.pyd') or dl.endswith('.dll'):
10611061
parts[-1] = bdist_egg.strip_module(parts[-1])
1062-
top_level[os.path.splitext(parts[0])[0]] = True
1062+
top_level.add([os.path.splitext(parts[0])[0]])
10631063
native_libs.append(src)
10641064
elif dl.endswith('.py') and old != 'SCRIPTS/':
1065-
top_level[os.path.splitext(parts[0])[0]] = True
1065+
top_level.add([os.path.splitext(parts[0])[0]])
10661066
to_compile.append(dst)
10671067
return dst
10681068
if not src.endswith('.pth'):
@@ -1484,14 +1484,14 @@ def get_site_dirs():
14841484
def expand_paths(inputs): # noqa: C901 # is too complex (11) # FIXME
14851485
"""Yield sys.path directories that might contain "old-style" packages"""
14861486

1487-
seen = {}
1487+
seen = set()
14881488

14891489
for dirname in inputs:
14901490
dirname = normalize_path(dirname)
14911491
if dirname in seen:
14921492
continue
14931493

1494-
seen[dirname] = True
1494+
seen.add(dirname)
14951495
if not os.path.isdir(dirname):
14961496
continue
14971497

@@ -1520,7 +1520,7 @@ def expand_paths(inputs): # noqa: C901 # is too complex (11) # FIXME
15201520
if line in seen:
15211521
continue
15221522

1523-
seen[line] = True
1523+
seen.add(line)
15241524
if not os.path.isdir(line):
15251525
continue
15261526

@@ -1622,7 +1622,7 @@ def __init__(self, filename, sitedirs=()):
16221622
def _load_raw(self):
16231623
paths = []
16241624
dirty = saw_import = False
1625-
seen = dict.fromkeys(self.sitedirs)
1625+
seen = set(self.sitedirs)
16261626
f = open(self.filename, 'rt', encoding=py39.LOCALE_ENCODING)
16271627
# ^-- Requires encoding="locale" instead of "utf-8" (python/cpython#77102).
16281628
for line in f:
@@ -1643,7 +1643,7 @@ def _load_raw(self):
16431643
dirty = True
16441644
paths.pop()
16451645
continue
1646-
seen[normalized_path] = True
1646+
seen.add(normalized_path)
16471647
f.close()
16481648
# remove any trailing empty/blank line
16491649
while paths and not paths[-1].strip():

setuptools/package_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def fetch_distribution( # noqa: C901 # is too complex (14) # FIXME
627627
"""
628628
# process a Requirement
629629
self.info("Searching for %s", requirement)
630-
skipped = {}
630+
skipped = set()
631631
dist = None
632632

633633
def find(req, env=None):
@@ -642,7 +642,7 @@ def find(req, env=None):
642642
"Skipping development or system egg: %s",
643643
dist,
644644
)
645-
skipped[dist] = True
645+
skipped.add(dist)
646646
continue
647647

648648
test = dist in req and (dist.precedence <= SOURCE_DIST or not source)

setuptools/tests/test_dist_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_output_dir(self, tmp_path, keep_egg_info):
122122
run_command("dist_info", "--output-dir", out, *opts, cwd=tmp_path)
123123
assert len(list(out.glob("*.dist-info"))) == 1
124124
assert len(list(tmp_path.glob("*.dist-info"))) == 0
125-
expected_egg_info = 1 if keep_egg_info else 0
125+
expected_egg_info = int(keep_egg_info)
126126
assert len(list(out.glob("*.egg-info"))) == expected_egg_info
127127
assert len(list(tmp_path.glob("*.egg-info"))) == 0
128128
assert len(list(out.glob("*.__bkp__"))) == 0

0 commit comments

Comments
 (0)