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.
pull/9174/head
Dylan Baker 3 years ago committed by Eli Schwartz
parent 1fc3d8608d
commit 278942a447
  1. 1
      .pylintrc
  2. 2
      mesonbuild/backend/xcodebackend.py
  3. 2
      mesonbuild/mparser.py

@ -12,6 +12,7 @@ enable=
bad-indentation,
bare-except,
compare-to-zero,
consider-iterating-dictionary,
dangerous-default-value,
deprecated-lambda,
len-as-condition,

@ -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')

@ -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

Loading…
Cancel
Save