Skip to content

Commit

Permalink
pylint: enable consider-iterating-dictionary
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcbaker authored and eli-schwartz committed Aug 31, 2021
1 parent 1fc3d86 commit 278942a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enable=
bad-indentation,
bare-except,
compare-to-zero,
consider-iterating-dictionary,
dangerous-default-value,
deprecated-lambda,
len-as-condition,
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/backend/xcodebackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ def generate_single_generator_phase(self, tname, t, genlist, generator_id, objec


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')
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/mparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def append(self, statement: BaseNode) -> None:
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
Expand Down

0 comments on commit 278942a

Please sign in to comment.