Skip to content

Commit 4575652

Browse files
committed
Use default flake8 config
1 parent 634383c commit 4575652

16 files changed

+119
-81
lines changed

pre_commit_hooks/check_builtin_literals.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,23 @@
2121
}
2222

2323

24-
BuiltinTypeCall = collections.namedtuple('BuiltinTypeCall', ['name', 'line', 'column'])
24+
Call = collections.namedtuple('Call', ['name', 'line', 'column'])
2525

2626

27-
class BuiltinTypeVisitor(ast.NodeVisitor):
27+
class Visitor(ast.NodeVisitor):
2828
def __init__(self, ignore=None, allow_dict_kwargs=True):
2929
# type: (Optional[Sequence[str]], bool) -> None
30-
self.builtin_type_calls = [] # type: List[BuiltinTypeCall]
30+
self.builtin_type_calls = [] # type: List[Call]
3131
self.ignore = set(ignore) if ignore else set()
3232
self.allow_dict_kwargs = allow_dict_kwargs
3333

3434
def _check_dict_call(self, node): # type: (ast.Call) -> bool
35-
36-
return self.allow_dict_kwargs and (getattr(node, 'kwargs', None) or getattr(node, 'keywords', None))
35+
return (
36+
self.allow_dict_kwargs and
37+
(getattr(node, 'kwargs', None) or getattr(node, 'keywords', None))
38+
)
3739

3840
def visit_Call(self, node): # type: (ast.Call) -> None
39-
4041
if not isinstance(node.func, ast.Name):
4142
# Ignore functions that are object attributes (`foo.bar()`).
4243
# Assume that if the user calls `builtins.list()`, they know what
@@ -49,15 +50,15 @@ def visit_Call(self, node): # type: (ast.Call) -> None
4950
elif node.args:
5051
return
5152
self.builtin_type_calls.append(
52-
BuiltinTypeCall(node.func.id, node.lineno, node.col_offset),
53+
Call(node.func.id, node.lineno, node.col_offset),
5354
)
5455

5556

56-
def check_file_for_builtin_type_constructors(filename, ignore=None, allow_dict_kwargs=True):
57-
# type: (str, Optional[Sequence[str]], bool) -> List[BuiltinTypeCall]
57+
def check_file(filename, ignore=None, allow_dict_kwargs=True):
58+
# type: (str, Optional[Sequence[str]], bool) -> List[Call]
5859
with open(filename, 'rb') as f:
5960
tree = ast.parse(f.read(), filename=filename)
60-
visitor = BuiltinTypeVisitor(ignore=ignore, allow_dict_kwargs=allow_dict_kwargs)
61+
visitor = Visitor(ignore=ignore, allow_dict_kwargs=allow_dict_kwargs)
6162
visitor.visit(tree)
6263
return visitor.builtin_type_calls
6364

@@ -73,14 +74,17 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
7374

7475
mutex = parser.add_mutually_exclusive_group(required=False)
7576
mutex.add_argument('--allow-dict-kwargs', action='store_true')
76-
mutex.add_argument('--no-allow-dict-kwargs', dest='allow_dict_kwargs', action='store_false')
77+
mutex.add_argument(
78+
'--no-allow-dict-kwargs',
79+
dest='allow_dict_kwargs', action='store_false',
80+
)
7781
mutex.set_defaults(allow_dict_kwargs=True)
7882

7983
args = parser.parse_args(argv)
8084

8185
rc = 0
8286
for filename in args.filenames:
83-
calls = check_file_for_builtin_type_constructors(
87+
calls = check_file(
8488
filename,
8589
ignore=args.ignore,
8690
allow_dict_kwargs=args.allow_dict_kwargs,
@@ -89,7 +93,8 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
8993
rc = rc or 1
9094
for call in calls:
9195
print(
92-
'{filename}:{call.line}:{call.column} - Replace {call.name}() with {replacement}'.format(
96+
'{filename}:{call.line}:{call.column}: '
97+
'replace {call.name}() with {replacement}'.format(
9398
filename=filename,
9499
call=call,
95100
replacement=BUILTIN_TYPES[call.name],

pre_commit_hooks/check_executables_have_shebangs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def check_has_shebang(path): # type: (str) -> int
1818
print(
1919
'{path}: marked executable but has no (or invalid) shebang!\n'
2020
" If it isn't supposed to be executable, try: chmod -x {quoted}\n"
21-
' If it is supposed to be executable, double-check its shebang.'.format(
21+
' If it is supposed to be executable, double-check its shebang.'
22+
.format(
2223
path=path,
2324
quoted=pipes.quote(path),
2425
),

pre_commit_hooks/check_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
1212
parser = argparse.ArgumentParser()
13-
parser.add_argument('filenames', nargs='*', help='JSON filenames to check.')
13+
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
1414
args = parser.parse_args(argv)
1515

1616
retval = 0

pre_commit_hooks/check_yaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
5050
'Implies --allow-multiple-documents'
5151
),
5252
)
53-
parser.add_argument('filenames', nargs='*', help='Yaml filenames to check.')
53+
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
5454
args = parser.parse_args(argv)
5555

5656
load_fn = LOAD_FNS[Key(multi=args.multi, unsafe=args.unsafe)]

pre_commit_hooks/detect_aws_credentials.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
from six.moves import configparser
1313

1414

15-
def get_aws_credential_files_from_env(): # type: () -> Set[str]
15+
def get_aws_cred_files_from_env(): # type: () -> Set[str]
1616
"""Extract credential file paths from environment variables."""
17-
files = set()
18-
for env_var in (
19-
'AWS_CONFIG_FILE', 'AWS_CREDENTIAL_FILE', 'AWS_SHARED_CREDENTIALS_FILE',
20-
'BOTO_CONFIG',
21-
):
22-
if env_var in os.environ:
23-
files.add(os.environ[env_var])
24-
return files
17+
return {
18+
os.environ[env_var]
19+
for env_var in (
20+
'AWS_CONFIG_FILE', 'AWS_CREDENTIAL_FILE',
21+
'AWS_SHARED_CREDENTIALS_FILE', 'BOTO_CONFIG',
22+
)
23+
if env_var in os.environ
24+
}
2525

2626

2727
def get_aws_secrets_from_env(): # type: () -> Set[str]
@@ -115,7 +115,7 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
115115

116116
# Add the credentials files configured via environment variables to the set
117117
# of files to to gather AWS secrets from.
118-
credential_files |= get_aws_credential_files_from_env()
118+
credential_files |= get_aws_cred_files_from_env()
119119

120120
keys = set() # type: Set[str]
121121
for credential_file in credential_files:

pre_commit_hooks/fix_encoding_pragma.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ def _to_disp(pragma): # type: (bytes) -> str
110110

111111

112112
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
113-
parser = argparse.ArgumentParser('Fixes the encoding pragma of python files')
113+
parser = argparse.ArgumentParser(
114+
'Fixes the encoding pragma of python files',
115+
)
114116
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
115117
parser.add_argument(
116118
'--pragma', default=DEFAULT_PRAGMA, type=_normalize_pragma,

pre_commit_hooks/pretty_format_json.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
from six import text_type
1616

1717

18-
def _get_pretty_format(contents, indent, ensure_ascii=True, sort_keys=True, top_keys=()):
19-
# type: (str, str, bool, bool, Sequence[str]) -> str
18+
def _get_pretty_format(
19+
contents, indent, ensure_ascii=True, sort_keys=True, top_keys=(),
20+
): # type: (str, str, bool, bool, Sequence[str]) -> str
2021
def pairs_first(pairs):
2122
# type: (Sequence[Tuple[str, str]]) -> Mapping[str, str]
2223
before = [pair for pair in pairs if pair[0] in top_keys]
@@ -29,7 +30,8 @@ def pairs_first(pairs):
2930
json.loads(contents, object_pairs_hook=pairs_first),
3031
indent=indent,
3132
ensure_ascii=ensure_ascii,
32-
separators=(',', ': '), # Workaround for https://bugs.python.org/issue16333
33+
# Workaround for https://bugs.python.org/issue16333
34+
separators=(',', ': '),
3335
)
3436
# Ensure unicode (Py2) and add the newline that dumps does not end with.
3537
return text_type(json_pretty) + '\n'
@@ -75,7 +77,10 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
7577
action='store_true',
7678
dest='no_ensure_ascii',
7779
default=False,
78-
help='Do NOT convert non-ASCII characters to Unicode escape sequences (\\uXXXX)',
80+
help=(
81+
'Do NOT convert non-ASCII characters to Unicode escape sequences '
82+
'(\\uXXXX)'
83+
),
7984
)
8085
parser.add_argument(
8186
'--no-sort-keys',

pre_commit_hooks/requirements_txt_fixer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ def fix_requirements(f): # type: (IO[bytes]) -> int
6161
# If we see a newline before any requirements, then this is a
6262
# top of file comment.
6363
if len(requirements) == 1 and line.strip() == b'':
64-
if len(requirement.comments) and requirement.comments[0].startswith(b'#'):
64+
if (
65+
len(requirement.comments) and
66+
requirement.comments[0].startswith(b'#')
67+
):
6568
requirement.value = b'\n'
6669
else:
6770
requirement.comments.append(line)

pre_commit_hooks/trailing_whitespace_fixer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
6060
if '' in md_args:
6161
parser.error('--markdown-linebreak-ext requires a non-empty argument')
6262
all_markdown = '*' in md_args
63-
# normalize all extensions; split at ',', lowercase, and force 1 leading '.'
63+
# normalize extensions; split at ',', lowercase, and force 1 leading '.'
6464
md_exts = [
6565
'.' + x.lower().lstrip('.') for x in ','.join(md_args).split(',')
6666
]
6767

68-
# reject probable "eaten" filename as extension (skip leading '.' with [1:])
68+
# reject probable "eaten" filename as extension: skip leading '.' with [1:]
6969
for ext in md_exts:
7070
if any(c in ext[1:] for c in r'./\:'):
7171
parser.error(

setup.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,34 @@
3232
entry_points={
3333
'console_scripts': [
3434
'autopep8-wrapper = pre_commit_hooks.autopep8_wrapper:main',
35-
'check-added-large-files = pre_commit_hooks.check_added_large_files:main',
35+
'check-added-large-files = pre_commit_hooks.check_added_large_files:main', # noqa: E501
3636
'check-ast = pre_commit_hooks.check_ast:main',
37-
'check-builtin-literals = pre_commit_hooks.check_builtin_literals:main',
38-
'check-byte-order-marker = pre_commit_hooks.check_byte_order_marker:main',
37+
'check-builtin-literals = pre_commit_hooks.check_builtin_literals:main', # noqa: E501
38+
'check-byte-order-marker = pre_commit_hooks.check_byte_order_marker:main', # noqa: E501
3939
'check-case-conflict = pre_commit_hooks.check_case_conflict:main',
40-
'check-docstring-first = pre_commit_hooks.check_docstring_first:main',
41-
'check-executables-have-shebangs = pre_commit_hooks.check_executables_have_shebangs:main',
40+
'check-docstring-first = pre_commit_hooks.check_docstring_first:main', # noqa: E501
41+
'check-executables-have-shebangs = pre_commit_hooks.check_executables_have_shebangs:main', # noqa: E501
4242
'check-json = pre_commit_hooks.check_json:main',
43-
'check-merge-conflict = pre_commit_hooks.check_merge_conflict:main',
43+
'check-merge-conflict = pre_commit_hooks.check_merge_conflict:main', # noqa: E501
4444
'check-symlinks = pre_commit_hooks.check_symlinks:main',
45-
'check-vcs-permalinks = pre_commit_hooks.check_vcs_permalinks:main',
45+
'check-vcs-permalinks = pre_commit_hooks.check_vcs_permalinks:main', # noqa: E501
4646
'check-xml = pre_commit_hooks.check_xml:main',
4747
'check-yaml = pre_commit_hooks.check_yaml:main',
48-
'debug-statement-hook = pre_commit_hooks.debug_statement_hook:main',
49-
'detect-aws-credentials = pre_commit_hooks.detect_aws_credentials:main',
48+
'debug-statement-hook = pre_commit_hooks.debug_statement_hook:main', # noqa: E501
49+
'detect-aws-credentials = pre_commit_hooks.detect_aws_credentials:main', # noqa: E501
5050
'detect-private-key = pre_commit_hooks.detect_private_key:main',
5151
'double-quote-string-fixer = pre_commit_hooks.string_fixer:main',
5252
'end-of-file-fixer = pre_commit_hooks.end_of_file_fixer:main',
53-
'file-contents-sorter = pre_commit_hooks.file_contents_sorter:main',
53+
'file-contents-sorter = pre_commit_hooks.file_contents_sorter:main', # noqa: E501
5454
'fix-encoding-pragma = pre_commit_hooks.fix_encoding_pragma:main',
55-
'forbid-new-submodules = pre_commit_hooks.forbid_new_submodules:main',
55+
'forbid-new-submodules = pre_commit_hooks.forbid_new_submodules:main', # noqa: E501
5656
'mixed-line-ending = pre_commit_hooks.mixed_line_ending:main',
5757
'name-tests-test = pre_commit_hooks.tests_should_end_in_test:main',
5858
'no-commit-to-branch = pre_commit_hooks.no_commit_to_branch:main',
5959
'pretty-format-json = pre_commit_hooks.pretty_format_json:main',
60-
'requirements-txt-fixer = pre_commit_hooks.requirements_txt_fixer:main',
60+
'requirements-txt-fixer = pre_commit_hooks.requirements_txt_fixer:main', # noqa: E501
6161
'sort-simple-yaml = pre_commit_hooks.sort_simple_yaml:main',
62-
'trailing-whitespace-fixer = pre_commit_hooks.trailing_whitespace_fixer:main',
62+
'trailing-whitespace-fixer = pre_commit_hooks.trailing_whitespace_fixer:main', # noqa: E501
6363
],
6464
},
6565
)

0 commit comments

Comments
 (0)