Skip to content

Commit

Permalink
chore: Use Python dict and list comprehensions (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss authored Apr 9, 2023
1 parent 6528b00 commit 179cc1b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pylib/gyp/MSVSProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, project_path, version, name, guid=None, platforms=None):
self.files_section = ["Files"]

# Keep a dict keyed on filename to speed up access.
self.files_dict = dict()
self.files_dict = {}

def AddToolFile(self, path):
"""Adds a tool file to the project.
Expand Down
18 changes: 7 additions & 11 deletions pylib/gyp/generator/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def _GetUnqualifiedToTargetMapping(all_targets, to_find):
result[extracted[1]] = all_targets[target_name]
if not to_find:
return result, []
return result, [x for x in to_find]
return result, list(to_find)


def _DoesTargetDependOnMatchingTargets(target):
Expand Down Expand Up @@ -683,11 +683,9 @@ def find_matching_test_target_names(self):
)
test_target_names_contains_all = "all" in self._test_target_names
if test_target_names_contains_all:
test_targets = [
x for x in (set(test_targets_no_all) | set(self._root_targets))
]
test_targets = list(set(test_targets_no_all) | set(self._root_targets))
else:
test_targets = [x for x in test_targets_no_all]
test_targets = list(test_targets_no_all)
print("supplied test_targets")
for target_name in self._test_target_names:
print("\t", target_name)
Expand All @@ -702,9 +700,9 @@ def find_matching_test_target_names(self):
if matching_test_targets_contains_all:
# Remove any of the targets for all that were not explicitly supplied,
# 'all' is subsequentely added to the matching names below.
matching_test_targets = [
x for x in (set(matching_test_targets) & set(test_targets_no_all))
]
matching_test_targets = list(
set(matching_test_targets) & set(test_targets_no_all)
)
print("matched test_targets")
for target in matching_test_targets:
print("\t", target.name)
Expand All @@ -729,9 +727,7 @@ def find_matching_compile_target_names(self):
self._supplied_target_names_no_all(), self._unqualified_mapping
)
if "all" in self._supplied_target_names():
supplied_targets = [
x for x in (set(supplied_targets) | set(self._root_targets))
]
supplied_targets = list(set(supplied_targets) | set(self._root_targets))
print("Supplied test_targets & compile_targets")
for target in supplied_targets:
print("\t", target.name)
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/generator/compile_commands_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def resolve(filename):
gyp.common.EncodePOSIXShellArgument(file),
)
)
commands.append(dict(command=command, directory=output_dir, file=file))
commands.append({"command": command, "directory": output_dir, "file": file})


def GenerateOutput(target_list, target_dicts, data, params):
Expand Down
6 changes: 3 additions & 3 deletions pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset=False):
else:
value = [i.replace("/", "\\") for i in value]
if not tools.get(tool_name):
tools[tool_name] = dict()
tools[tool_name] = {}
tool = tools[tool_name]
if setting == "CompileAsWinRT":
return
Expand Down Expand Up @@ -1186,7 +1186,7 @@ def _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config):
precompiled_header = config.get("msvs_precompiled_header")

# Prepare the list of tools as a dictionary.
tools = dict()
tools = {}
# Add in user specified msvs_settings.
msvs_settings = config.get("msvs_settings", {})
MSVSSettings.ValidateMSVSSettings(msvs_settings)
Expand Down Expand Up @@ -1810,7 +1810,7 @@ def _GetPathDict(root, path):
parent, folder = os.path.split(path)
parent_dict = _GetPathDict(root, parent)
if folder not in parent_dict:
parent_dict[folder] = dict()
parent_dict[folder] = {}
return parent_dict[folder]


Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ select = [
# "TRY", # tryceratops
]
ignore = [
"C408",
"C416",
"PLC1901",
"PLR0402",
"PLR2004",
Expand Down
4 changes: 2 additions & 2 deletions tools/pretty_sln.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def BuildProject(project, built, projects, deps):

def ParseSolution(solution_file):
# All projects, their clsid and paths.
projects = dict()
projects = {}

# A list of dependencies associated with a project.
dependencies = dict()
dependencies = {}

# Regular expressions that matches the SLN format.
# The first line of a project definition.
Expand Down
2 changes: 1 addition & 1 deletion tools/pretty_vcproj.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

__author__ = "nsylvain (Nicolas Sylvain)"
ARGUMENTS = None
REPLACEMENTS = dict()
REPLACEMENTS = {}


def cmp(x, y):
Expand Down

0 comments on commit 179cc1b

Please sign in to comment.