Prefer iter(dict) instead of dict.keys()

They are equivalent for iterating so remove the additional function
call.

Pattern identified as outdated by Lennart Regebro's PyCon 2017 talk
"Prehistoric Patterns in Python"

https://www.youtube.com/watch?v=V5-JH23Vk0I
This commit is contained in:
Jon Dufresne 2017-05-27 11:54:06 -07:00
parent d890b8b683
commit db4f71288e
5 changed files with 6 additions and 6 deletions

View file

@ -261,7 +261,7 @@ class Application(object):
List of filenames to process
"""
if self.running_against_diff:
files = sorted(self.parsed_diff.keys())
files = sorted(self.parsed_diff)
self.file_checker_manager.start(files)
self.file_checker_manager.run()
LOG.info('Finished running')

View file

@ -36,4 +36,4 @@ def install(option, option_string, value, parser):
def choices():
"""Return the list of VCS choices."""
return list(_INSTALLERS.keys())
return list(_INSTALLERS)

View file

@ -90,7 +90,7 @@ class TrieNode(object):
if not self.children:
return
for prefix in sorted(self.children.keys()):
for prefix in sorted(self.children):
child = self.children[prefix]
yield child
for child in child.traverse():

View file

@ -17,7 +17,7 @@ class Statistics(object):
:rtype:
list(str)
"""
return sorted({key.code for key in self._store.keys()})
return sorted({key.code for key in self._store})
def record(self, error):
"""Add the fact that the error was seen in the file.
@ -55,7 +55,7 @@ class Statistics(object):
:returns:
Generator of instances of :class:`Statistic`
"""
matching_errors = sorted(key for key in self._store.keys()
matching_errors = sorted(key for key in self._store
if key.matches(prefix, filename))
for error_code in matching_errors:
yield self._store[error_code]

View file

@ -205,7 +205,7 @@ class FakePluginTypeManager(manager.NotifierBuilderMixin):
def __init__(self, manager):
"""Initialize with our fake manager."""
self.names = sorted(manager.keys())
self.names = sorted(manager)
self.manager = manager