Skip to content

Commit a44f208

Browse files
committed
Merge pull request pypa/distutils#252 from Avasam/Use-set-instead-of-True-only-dict
Use `set` instead of `True`-only `dict`
2 parents a4bdc72 + b26d5e4 commit a44f208

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
@@ -696,12 +696,12 @@ def handle_display_options(self, option_order):
696696
# display that metadata in the order in which the user supplied the
697697
# metadata options.
698698
any_display_options = 0
699-
is_display_option = {}
699+
is_display_option = set()
700700
for option in self.display_options:
701-
is_display_option[option[0]] = 1
701+
is_display_option.add(option[0])
702702

703703
for opt, val in option_order:
704-
if val and is_display_option.get(opt):
704+
if val and opt in is_display_option:
705705
opt = translate_longopt(opt)
706706
value = getattr(self.metadata, "get_" + opt)()
707707
if opt in ('keywords', 'platforms'):
@@ -742,13 +742,13 @@ def print_commands(self):
742742
import distutils.command
743743

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

749749
extra_commands = []
750750
for cmd in self.cmdclass.keys():
751-
if not is_std.get(cmd):
751+
if cmd not in is_std:
752752
extra_commands.append(cmd)
753753

754754
max_length = 0
@@ -773,13 +773,13 @@ def get_command_list(self):
773773
import distutils.command
774774

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

780780
extra_commands = []
781781
for cmd in self.cmdclass.keys():
782-
if not is_std.get(cmd):
782+
if cmd not in is_std:
783783
extra_commands.append(cmd)
784784

785785
rv = []

0 commit comments

Comments
 (0)