Skip to content

Commit

Permalink
Merge pull request #252 from Avasam/Use-set-instead-of-True-only-dict
Browse files Browse the repository at this point in the history
Use `set` instead of `True`-only `dict`
  • Loading branch information
jaraco authored Jun 27, 2024
2 parents 56d56c0 + 7978896 commit 9b2eb51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions distutils/dir_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# cache for by mkpath() -- in addition to cheapening redundant calls,
# eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
_path_created = {}
_path_created = set()


def mkpath(name, mode=0o777, verbose=1, dry_run=0): # noqa: C901
Expand Down Expand Up @@ -45,7 +45,7 @@ def mkpath(name, mode=0o777, verbose=1, dry_run=0): # noqa: C901
created_dirs = []
if os.path.isdir(name) or name == '':
return created_dirs
if _path_created.get(os.path.abspath(name)):
if os.path.abspath(name) in _path_created:
return created_dirs

(head, tail) = os.path.split(name)
Expand All @@ -63,7 +63,7 @@ def mkpath(name, mode=0o777, verbose=1, dry_run=0): # noqa: C901
head = os.path.join(head, d)
abs_head = os.path.abspath(head)

if _path_created.get(abs_head):
if abs_head in _path_created:
continue

if verbose >= 1:
Expand All @@ -79,7 +79,7 @@ def mkpath(name, mode=0o777, verbose=1, dry_run=0): # noqa: C901
)
created_dirs.append(head)

_path_created[abs_head] = 1
_path_created.add(abs_head)
return created_dirs


Expand Down Expand Up @@ -222,7 +222,7 @@ def remove_tree(directory, verbose=1, dry_run=0):
# remove dir from cache if it's already there
abspath = os.path.abspath(cmd[1])
if abspath in _path_created:
_path_created.pop(abspath)
_path_created.remove(abspath)
except OSError as exc:
log.warning("error removing %s: %s", directory, exc)

Expand Down
18 changes: 9 additions & 9 deletions distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,12 @@ def handle_display_options(self, option_order):
# display that metadata in the order in which the user supplied the
# metadata options.
any_display_options = 0
is_display_option = {}
is_display_option = set()
for option in self.display_options:
is_display_option[option[0]] = 1
is_display_option.add(option[0])

for opt, val in option_order:
if val and is_display_option.get(opt):
if val and opt in is_display_option:
opt = translate_longopt(opt)
value = getattr(self.metadata, "get_" + opt)()
if opt in ('keywords', 'platforms'):
Expand Down Expand Up @@ -742,13 +742,13 @@ def print_commands(self):
import distutils.command

std_commands = distutils.command.__all__
is_std = {}
is_std = set()
for cmd in std_commands:
is_std[cmd] = 1
is_std.add(cmd)

extra_commands = []
for cmd in self.cmdclass.keys():
if not is_std.get(cmd):
if cmd not in is_std:
extra_commands.append(cmd)

max_length = 0
Expand All @@ -773,13 +773,13 @@ def get_command_list(self):
import distutils.command

std_commands = distutils.command.__all__
is_std = {}
is_std = set()
for cmd in std_commands:
is_std[cmd] = 1
is_std.add(cmd)

extra_commands = []
for cmd in self.cmdclass.keys():
if not is_std.get(cmd):
if cmd not in is_std:
extra_commands.append(cmd)

rv = []
Expand Down

0 comments on commit 9b2eb51

Please sign in to comment.