aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mparser.py
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 /mesonbuild/mparser.py
parent1fc3d8608d9d278c9faf8ccf6aecf33cc7e92c26 (diff)
downloadmeson-278942a44703aff6b643426b09a9012460719622.zip
meson-278942a44703aff6b643426b09a9012460719622.tar.gz
meson-278942a44703aff6b643426b09a9012460719622.tar.bz2
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.
Diffstat (limited to 'mesonbuild/mparser.py')
-rw-r--r--mesonbuild/mparser.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index 1079682..1617dd1 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