From 0ab0a4d2e3f66c94eacf57d9c42ce55c7b60a550 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 22 May 2024 12:12:36 -0400 Subject: [PATCH] Use set instead of True-only dict for non-public names --- pkg_resources/__init__.py | 10 +++++----- setuptools/command/easy_install.py | 16 ++++++++-------- setuptools/package_index.py | 4 ++-- setuptools/tests/test_dist_info.py | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index c86d9f095c..d29b127e15 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -719,7 +719,7 @@ def __iter__(self): The yield order is the order in which the items' path entries were added to the working set. """ - seen = {} + seen = set() for item in self.entries: if item not in self.entry_keys: # workaround a cache issue @@ -727,7 +727,7 @@ def __iter__(self): for key in self.entry_keys[item]: if key not in seen: - seen[key] = 1 + seen.add(key) yield self.by_key[key] def add( @@ -803,7 +803,7 @@ def resolve( # set up the stack requirements = list(requirements)[::-1] # set of processed requirements - processed = {} + processed = set() # key -> dist best = {} to_activate = [] @@ -837,7 +837,7 @@ def resolve( required_by[new_requirement].add(req.project_name) req_extras[new_requirement] = req.extras - processed[req] = True + processed.add(req) # return list of distros to activate return to_activate @@ -1310,7 +1310,7 @@ def get_cache_path(self, archive_name: str, names: Iterable[str] = ()): self._warn_unsafe_extraction_path(extract_path) - self.cached_files[target_path] = 1 + self.cached_files[target_path] = True return target_path @staticmethod diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 41ff382fe4..849295e166 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1046,7 +1046,7 @@ def exe_to_egg(self, dist_filename, egg_tmp): # noqa: C901 prefixes = get_exe_prefixes(dist_filename) to_compile = [] native_libs = [] - top_level = {} + top_level = set() def process(src, dst): s = src.lower() @@ -1058,10 +1058,10 @@ def process(src, dst): dl = dst.lower() if dl.endswith('.pyd') or dl.endswith('.dll'): parts[-1] = bdist_egg.strip_module(parts[-1]) - top_level[os.path.splitext(parts[0])[0]] = 1 + top_level.add([os.path.splitext(parts[0])[0]]) native_libs.append(src) elif dl.endswith('.py') and old != 'SCRIPTS/': - top_level[os.path.splitext(parts[0])[0]] = 1 + top_level.add([os.path.splitext(parts[0])[0]]) to_compile.append(dst) return dst if not src.endswith('.pth'): @@ -1483,14 +1483,14 @@ def get_site_dirs(): def expand_paths(inputs): # noqa: C901 # is too complex (11) # FIXME """Yield sys.path directories that might contain "old-style" packages""" - seen = {} + seen = set() for dirname in inputs: dirname = normalize_path(dirname) if dirname in seen: continue - seen[dirname] = 1 + seen.add(dirname) if not os.path.isdir(dirname): continue @@ -1519,7 +1519,7 @@ def expand_paths(inputs): # noqa: C901 # is too complex (11) # FIXME if line in seen: continue - seen[line] = 1 + seen.add(line) if not os.path.isdir(line): continue @@ -1621,7 +1621,7 @@ def __init__(self, filename, sitedirs=()): def _load_raw(self): paths = [] dirty = saw_import = False - seen = dict.fromkeys(self.sitedirs) + seen = set(self.sitedirs) f = open(self.filename, 'rt', encoding=py39.LOCALE_ENCODING) # ^-- Requires encoding="locale" instead of "utf-8" (python/cpython#77102). for line in f: @@ -1642,7 +1642,7 @@ def _load_raw(self): dirty = True paths.pop() continue - seen[normalized_path] = 1 + seen.add(normalized_path) f.close() # remove any trailing empty/blank line while paths and not paths[-1].strip(): diff --git a/setuptools/package_index.py b/setuptools/package_index.py index c3ffee41a7..c91e419923 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -627,7 +627,7 @@ def fetch_distribution( # noqa: C901 # is too complex (14) # FIXME """ # process a Requirement self.info("Searching for %s", requirement) - skipped = {} + skipped = set() dist = None def find(req, env=None): @@ -642,7 +642,7 @@ def find(req, env=None): "Skipping development or system egg: %s", dist, ) - skipped[dist] = 1 + skipped.add(dist) continue test = dist in req and (dist.precedence <= SOURCE_DIST or not source) diff --git a/setuptools/tests/test_dist_info.py b/setuptools/tests/test_dist_info.py index c6fe97e2ba..44be6c3284 100644 --- a/setuptools/tests/test_dist_info.py +++ b/setuptools/tests/test_dist_info.py @@ -122,7 +122,7 @@ def test_output_dir(self, tmp_path, keep_egg_info): run_command("dist_info", "--output-dir", out, *opts, cwd=tmp_path) assert len(list(out.glob("*.dist-info"))) == 1 assert len(list(tmp_path.glob("*.dist-info"))) == 0 - expected_egg_info = 1 if keep_egg_info else 0 + expected_egg_info = int(keep_egg_info) assert len(list(out.glob("*.egg-info"))) == expected_egg_info assert len(list(tmp_path.glob("*.egg-info"))) == 0 assert len(list(out.glob("*.__bkp__"))) == 0