Skip to content

Commit

Permalink
Use set instead of True-only dict for non-public names
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed May 22, 2024
1 parent 52d7324 commit 0ab0a4d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,15 +719,15 @@ 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
continue

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(
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions setuptools/package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_dist_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ab0a4d

Please sign in to comment.