Skip to content

Commit b26d5e4

Browse files
Avasamjaraco
authored andcommitted
Use set instead of True-only dict
1 parent 8980c8c commit b26d5e4

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

distutils/dir_util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

1515

1616
def mkpath(name, mode=0o777, verbose=1, dry_run=0): # noqa: C901
@@ -45,7 +45,7 @@ def mkpath(name, mode=0o777, verbose=1, dry_run=0): # noqa: C901
4545
created_dirs = []
4646
if os.path.isdir(name) or name == '':
4747
return created_dirs
48-
if _path_created.get(os.path.abspath(name)):
48+
if os.path.abspath(name) in _path_created:
4949
return created_dirs
5050

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

66-
if _path_created.get(abs_head):
66+
if abs_head in _path_created:
6767
continue
6868

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

82-
_path_created[abs_head] = 1
82+
_path_created.add(abs_head)
8383
return created_dirs
8484

8585

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

distutils/dist.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,12 @@ def handle_display_options(self, option_order):
694694
# display that metadata in the order in which the user supplied the
695695
# metadata options.
696696
any_display_options = 0
697-
is_display_option = {}
697+
is_display_option = set()
698698
for option in self.display_options:
699-
is_display_option[option[0]] = 1
699+
is_display_option.add(option[0])
700700

701701
for opt, val in option_order:
702-
if val and is_display_option.get(opt):
702+
if val and opt in is_display_option:
703703
opt = translate_longopt(opt)
704704
value = getattr(self.metadata, "get_" + opt)()
705705
if opt in ('keywords', 'platforms'):
@@ -740,13 +740,13 @@ def print_commands(self):
740740
import distutils.command
741741

742742
std_commands = distutils.command.__all__
743-
is_std = {}
743+
is_std = set()
744744
for cmd in std_commands:
745-
is_std[cmd] = 1
745+
is_std.add(cmd)
746746

747747
extra_commands = []
748748
for cmd in self.cmdclass.keys():
749-
if not is_std.get(cmd):
749+
if cmd not in is_std:
750750
extra_commands.append(cmd)
751751

752752
max_length = 0
@@ -771,13 +771,13 @@ def get_command_list(self):
771771
import distutils.command
772772

773773
std_commands = distutils.command.__all__
774-
is_std = {}
774+
is_std = set()
775775
for cmd in std_commands:
776-
is_std[cmd] = 1
776+
is_std.add(cmd)
777777

778778
extra_commands = []
779779
for cmd in self.cmdclass.keys():
780-
if not is_std.get(cmd):
780+
if cmd not in is_std:
781781
extra_commands.append(cmd)
782782

783783
rv = []

0 commit comments

Comments
 (0)