Skip to content

Commit 0ab0a4d

Browse files
committed
Use set instead of True-only dict for non-public names
1 parent 52d7324 commit 0ab0a4d

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
@@ -719,15 +719,15 @@ def __iter__(self):
719719
The yield order is the order in which the items' path entries were
720720
added to the working set.
721721
"""
722-
seen = {}
722+
seen = set()
723723
for item in self.entries:
724724
if item not in self.entry_keys:
725725
# workaround a cache issue
726726
continue
727727

728728
for key in self.entry_keys[item]:
729729
if key not in seen:
730-
seen[key] = 1
730+
seen.add(key)
731731
yield self.by_key[key]
732732

733733
def add(
@@ -803,7 +803,7 @@ def resolve(
803803
# set up the stack
804804
requirements = list(requirements)[::-1]
805805
# set of processed requirements
806-
processed = {}
806+
processed = set()
807807
# key -> dist
808808
best = {}
809809
to_activate = []
@@ -837,7 +837,7 @@ def resolve(
837837
required_by[new_requirement].add(req.project_name)
838838
req_extras[new_requirement] = req.extras
839839

840-
processed[req] = True
840+
processed.add(req)
841841

842842
# return list of distros to activate
843843
return to_activate
@@ -1310,7 +1310,7 @@ def get_cache_path(self, archive_name: str, names: Iterable[str] = ()):
13101310

13111311
self._warn_unsafe_extraction_path(extract_path)
13121312

1313-
self.cached_files[target_path] = 1
1313+
self.cached_files[target_path] = True
13141314
return target_path
13151315

13161316
@staticmethod

setuptools/command/easy_install.py

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

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

1486-
seen = {}
1486+
seen = set()
14871487

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

1493-
seen[dirname] = 1
1493+
seen.add(dirname)
14941494
if not os.path.isdir(dirname):
14951495
continue
14961496

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

1522-
seen[line] = 1
1522+
seen.add(line)
15231523
if not os.path.isdir(line):
15241524
continue
15251525

@@ -1621,7 +1621,7 @@ def __init__(self, filename, sitedirs=()):
16211621
def _load_raw(self):
16221622
paths = []
16231623
dirty = saw_import = False
1624-
seen = dict.fromkeys(self.sitedirs)
1624+
seen = set(self.sitedirs)
16251625
f = open(self.filename, 'rt', encoding=py39.LOCALE_ENCODING)
16261626
# ^-- Requires encoding="locale" instead of "utf-8" (python/cpython#77102).
16271627
for line in f:
@@ -1642,7 +1642,7 @@ def _load_raw(self):
16421642
dirty = True
16431643
paths.pop()
16441644
continue
1645-
seen[normalized_path] = 1
1645+
seen.add(normalized_path)
16461646
f.close()
16471647
# remove any trailing empty/blank line
16481648
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] = 1
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)