summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-08-31 09:37:14 -0700
committerEli Schwartz <eschwartz93@gmail.com>2021-08-31 16:28:54 -0400
commit278942a44703aff6b643426b09a9012460719622 (patch)
tree5019a9ba34a83ad5cef34efc8325955f05b9cef3
parent1fc3d8608d9d278c9faf8ccf6aecf33cc7e92c26 (diff)
downloadmeson-278942a44703aff6b643426b09a9012460719622.tar.gz
pylint: enable consider-iterating-dictionary
This didn't actually catch what it's supposed to, which is cases of: ```python for x in dict.keys(): y = dict[x] ``` But it did catch one unnecessary use of keys(), and one case where we were doing something in an inefficient way. I've rewritten: ```python if name.value in [x.value for x in self.kwargs.keys() if isinstance(x, IdNode)]: ``` as ``python if any((isinstance(x, IdNode) and name.value == x.value) for x in self.kwargs): ``` Which avoids doing two iterations, one to build the list, and a second to do a search for name.value in said list, which does a single short circuiting walk, as any returns as soon as one check returns True.
-rw-r--r--.pylintrc1
-rw-r--r--mesonbuild/backend/xcodebackend.py2
-rw-r--r--mesonbuild/mparser.py2
3 files changed, 3 insertions, 2 deletions
diff --git a/.pylintrc b/.pylintrc
index 31ac9259b..423066a38 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -12,6 +12,7 @@ enable=
bad-indentation,
bare-except,
compare-to-zero,
+ consider-iterating-dictionary,
dangerous-default-value,
deprecated-lambda,
len-as-condition,
diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py
index 01053c185..b1a89567d 100644
--- a/mesonbuild/backend/xcodebackend.py
+++ b/mesonbuild/backend/xcodebackend.py
@@ -1282,7 +1282,7 @@ class XCodeBackend(backends.Backend):
def generate_pbx_sources_build_phase(self, objects_dict):
- for name in self.source_phase.keys():
+ for name in self.source_phase:
phase_dict = PbxDict()
t = self.build_targets[name]
objects_dict.add_item(t.buildphasemap[name], phase_dict, 'Sources')
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index 10796827c..1617dd1fa 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -324,7 +324,7 @@ class ArgumentNode(BaseNode):
self.arguments += [statement]
def set_kwarg(self, name: IdNode, value: BaseNode) -> None:
- if name.value in [x.value for x in self.kwargs.keys() if isinstance(x, IdNode)]:
+ if any((isinstance(x, IdNode) and name.value == x.value) for x in self.kwargs):
mlog.warning(f'Keyword argument "{name.value}" defined multiple times.', location=self)
mlog.warning('This will be an error in future Meson releases.')
self.kwargs[name] = value