Clean up some uses of set, list, and dict

* Use set literals instead of set([...])
* Avoid list(sorted(...)) as sorted returns a list
* Replace dict() with dict literal
This commit is contained in:
Jon Dufresne 2017-05-01 07:03:21 -07:00
parent 23b1f37ffd
commit 541bac6a82
8 changed files with 41 additions and 41 deletions

View file

@ -19,7 +19,7 @@ from flake8 import utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
SERIAL_RETRY_ERRNOS = set([ SERIAL_RETRY_ERRNOS = {
# ENOSPC: Added by sigmavirus24 # ENOSPC: Added by sigmavirus24
# > On some operating systems (OSX), multiprocessing may cause an # > On some operating systems (OSX), multiprocessing may cause an
# > ENOSPC error while trying to trying to create a Semaphore. # > ENOSPC error while trying to trying to create a Semaphore.
@ -32,7 +32,7 @@ SERIAL_RETRY_ERRNOS = set([
# on the lines before the error code and always append your error # on the lines before the error code and always append your error
# code. Further, please always add a trailing `,` to reduce the visual # code. Further, please always add a trailing `,` to reduce the visual
# noise in diffs. # noise in diffs.
]) }
class Manager(object): class Manager(object):

View file

@ -25,7 +25,7 @@ IGNORE = (
SELECT = ('E', 'F', 'W', 'C90') SELECT = ('E', 'F', 'W', 'C90')
MAX_LINE_LENGTH = 79 MAX_LINE_LENGTH = 79
TRUTHY_VALUES = set(['true', '1', 't']) TRUTHY_VALUES = {'true', '1', 't'}
# Other constants # Other constants
WHITESPACE = frozenset(' \t') WHITESPACE = frozenset(' \t')

View file

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

View file

@ -133,10 +133,10 @@ class MergedConfigParser(object):
#: Set of types that should use the #: Set of types that should use the
#: :meth:`~configparser.RawConfigParser.getint` method. #: :meth:`~configparser.RawConfigParser.getint` method.
GETINT_TYPES = set(['int', 'count']) GETINT_TYPES = {'int', 'count'}
#: Set of actions that should use the #: Set of actions that should use the
#: :meth:`~configparser.RawConfigParser.getbool` method. #: :meth:`~configparser.RawConfigParser.getbool` method.
GETBOOL_ACTIONS = set(['store_true', 'store_false']) GETBOOL_ACTIONS = {'store_true', 'store_false'}
def __init__(self, option_manager, extra_config_files=None, args=None): def __init__(self, option_manager, extra_config_files=None, args=None):
"""Initialize the MergedConfigParser instance. """Initialize the MergedConfigParser instance.

View file

@ -17,35 +17,35 @@ import pyflakes.checker
from flake8 import utils from flake8 import utils
FLAKE8_PYFLAKES_CODES = dict([line.split()[::-1] for line in ( FLAKE8_PYFLAKES_CODES = {
'F401 UnusedImport', 'UnusedImport': 'F401',
'F402 ImportShadowedByLoopVar', 'ImportShadowedByLoopVar': 'F402',
'F403 ImportStarUsed', 'ImportStarUsed': 'F403',
'F404 LateFutureImport', 'LateFutureImport': 'F404',
'F405 ImportStarUsage', 'ImportStarUsage': 'F405',
'F406 ImportStarNotPermitted', 'ImportStarNotPermitted': 'F406',
'F407 FutureFeatureNotDefined', 'FutureFeatureNotDefined': 'F407',
'F601 MultiValueRepeatedKeyLiteral', 'MultiValueRepeatedKeyLiteral': 'F601',
'F602 MultiValueRepeatedKeyVariable', 'MultiValueRepeatedKeyVariable': 'F602',
'F621 TooManyExpressionsInStarredAssignment', 'TooManyExpressionsInStarredAssignment': 'F621',
'F622 TwoStarredExpressions', 'TwoStarredExpressions': 'F622',
'F631 AssertTuple', 'AssertTuple': 'F631',
'F701 BreakOutsideLoop', 'BreakOutsideLoop': 'F701',
'F702 ContinueOutsideLoop', 'ContinueOutsideLoop': 'F702',
'F703 ContinueInFinally', 'ContinueInFinally': 'F703',
'F704 YieldOutsideFunction', 'YieldOutsideFunction': 'F704',
'F705 ReturnWithArgsInsideGenerator', 'ReturnWithArgsInsideGenerator': 'F705',
'F706 ReturnOutsideFunction', 'ReturnOutsideFunction': 'F706',
'F707 DefaultExceptNotLast', 'DefaultExceptNotLast': 'F707',
'F721 DoctestSyntaxError', 'DoctestSyntaxError': 'F721',
'F811 RedefinedWhileUnused', 'RedefinedWhileUnused': 'F811',
'F812 RedefinedInListComp', 'RedefinedInListComp': 'F812',
'F821 UndefinedName', 'UndefinedName': 'F821',
'F822 UndefinedExport', 'UndefinedExport': 'F822',
'F823 UndefinedLocal', 'UndefinedLocal': 'F823',
'F831 DuplicateArgument', 'DuplicateArgument': 'F831',
'F841 UnusedVariable', 'UnusedVariable': 'F841',
)]) }
def patch_pyflakes(): def patch_pyflakes():

View file

@ -17,7 +17,7 @@ class Statistics(object):
:rtype: :rtype:
list(str) list(str)
""" """
return list(sorted(set(key.code for key in self._store.keys()))) return sorted({key.code for key in self._store.keys()})
def record(self, error): def record(self, error):
"""Add the fact that the error was seen in the file. """Add the fact that the error was seen in the file.

View file

@ -45,8 +45,8 @@ def test_information(system, pyversion, pyimpl):
}, },
} }
option_manager = mock.Mock( option_manager = mock.Mock(
registered_plugins=set([('pycodestyle', '2.0.0'), registered_plugins={('pycodestyle', '2.0.0'),
('mccabe', '0.5.9')]), ('mccabe', '0.5.9')},
version='3.1.0', version='3.1.0',
) )
assert expected == debug.information(option_manager) assert expected == debug.information(option_manager)

View file

@ -209,9 +209,9 @@ def test_extend_default_ignore(optmanager):
assert optmanager.extended_default_ignore == set() assert optmanager.extended_default_ignore == set()
optmanager.extend_default_ignore(['T100', 'T101', 'T102']) optmanager.extend_default_ignore(['T100', 'T101', 'T102'])
assert optmanager.extended_default_ignore == set(['T100', assert optmanager.extended_default_ignore == {'T100',
'T101', 'T101',
'T102']) 'T102'}
def test_parse_known_args(optmanager): def test_parse_known_args(optmanager):