Skip to content

Commit ba75867

Browse files
committed
py27+ syntax improvements
1 parent 0a93f3b commit ba75867

File tree

9 files changed

+31
-34
lines changed

9 files changed

+31
-34
lines changed

pre_commit/commands/autoupdate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def _update_repository(repo_config, runner):
5050
new_repo = Repository.create(new_config, runner.store)
5151

5252
# See if any of our hooks were deleted with the new commits
53-
hooks = set(hook_id for hook_id, _ in repo.hooks)
54-
hooks_missing = hooks - (hooks & set(new_repo.manifest.hooks.keys()))
53+
hooks = {hook_id for hook_id, _ in repo.hooks}
54+
hooks_missing = hooks - (hooks & set(new_repo.manifest.hooks))
5555
if hooks_missing:
5656
raise RepositoryCannotBeUpdatedError(
5757
'Cannot update because the tip of master is missing these hooks:\n'

pre_commit/commands/run.py

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

2020
def _get_skips(environ):
2121
skips = environ.get('SKIP', '')
22-
return set(skip.strip() for skip in skips.split(',') if skip.strip())
22+
return {skip.strip() for skip in skips.split(',') if skip.strip()}
2323

2424

2525
def _hook_msg_start(hook, verbose):

pre_commit/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ def get_files_matching(all_file_list_strategy):
8888
def wrapper(include_expr, exclude_expr):
8989
include_regex = re.compile(include_expr)
9090
exclude_regex = re.compile(exclude_expr)
91-
return set(
91+
return {
9292
filename
9393
for filename in all_file_list_strategy()
9494
if (
9595
include_regex.search(filename) and
9696
not exclude_regex.search(filename) and
9797
os.path.lexists(filename)
9898
)
99-
)
99+
}
100100
return wrapper
101101

102102

pre_commit/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ def manifest_contents(self):
2121

2222
@cached_property
2323
def hooks(self):
24-
return dict((hook['id'], hook) for hook in self.manifest_contents)
24+
return {hook['id']: hook for hook in self.manifest_contents}

pre_commit/repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def sha(self):
5757

5858
@cached_property
5959
def languages(self):
60-
return set(
60+
return {
6161
(hook['language'], hook['language_version'])
6262
for _, hook in self.hooks
63-
)
63+
}
6464

6565
@cached_property
6666
def additional_dependencies(self):

pre_commit/util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def no_git_env():
7575
# while running pre-commit hooks in submodules.
7676
# GIT_DIR: Causes git clone to clone wrong thing
7777
# GIT_INDEX_FILE: Causes 'error invalid object ...' during commit
78-
return dict(
79-
(k, v) for k, v in os.environ.items() if not k.startswith('GIT_')
80-
)
78+
return {
79+
k: v for k, v in os.environ.items() if not k.startswith('GIT_')
80+
}
8181

8282

8383
@contextlib.contextmanager
@@ -164,10 +164,10 @@ def cmd_output(*cmd, **kwargs):
164164

165165
# py2/py3 on windows are more strict about the types here
166166
cmd = tuple(five.n(arg) for arg in cmd)
167-
kwargs['env'] = dict(
168-
(five.n(key), five.n(value))
167+
kwargs['env'] = {
168+
five.n(key): five.n(value)
169169
for key, value in kwargs.pop('env', {}).items()
170-
) or None
170+
} or None
171171

172172
try:
173173
cmd = parse_shebang.normalize_cmd(cmd)

tests/commands/run_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,13 @@ def test_compute_cols(hooks, verbose, expected):
339339
@pytest.mark.parametrize(
340340
('environ', 'expected_output'),
341341
(
342-
({}, set([])),
343-
({'SKIP': ''}, set([])),
344-
({'SKIP': ','}, set([])),
345-
({'SKIP': ',foo'}, set(['foo'])),
346-
({'SKIP': 'foo'}, set(['foo'])),
347-
({'SKIP': 'foo,bar'}, set(['foo', 'bar'])),
348-
({'SKIP': ' foo , bar'}, set(['foo', 'bar'])),
342+
({}, set()),
343+
({'SKIP': ''}, set()),
344+
({'SKIP': ','}, set()),
345+
({'SKIP': ',foo'}, {'foo'}),
346+
({'SKIP': 'foo'}, {'foo'}),
347+
({'SKIP': 'foo,bar'}, {'foo', 'bar'}),
348+
({'SKIP': ' foo , bar'}, {'foo', 'bar'}),
349349
),
350350
)
351351
def test_get_skips(environ, expected_output):

tests/git_test.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,22 @@ def get_filenames():
8080

8181
def test_get_files_matching_base(get_files_matching_func):
8282
ret = get_files_matching_func('', '^$')
83-
assert ret == set([
83+
assert ret == {
8484
'pre_commit/main.py',
8585
'pre_commit/git.py',
8686
'hooks.yaml',
8787
'testing/test_symlink'
88-
])
88+
}
8989

9090

9191
def test_get_files_matching_total_match(get_files_matching_func):
9292
ret = get_files_matching_func('^.*\\.py$', '^$')
93-
assert ret == set([
94-
'pre_commit/main.py',
95-
'pre_commit/git.py',
96-
])
93+
assert ret == {'pre_commit/main.py', 'pre_commit/git.py'}
9794

9895

9996
def test_does_search_instead_of_match(get_files_matching_func):
10097
ret = get_files_matching_func('\\.yaml$', '^$')
101-
assert ret == set(['hooks.yaml'])
98+
assert ret == {'hooks.yaml'}
10299

103100

104101
def test_does_not_include_deleted_fileS(get_files_matching_func):
@@ -108,7 +105,7 @@ def test_does_not_include_deleted_fileS(get_files_matching_func):
108105

109106
def test_exclude_removes_files(get_files_matching_func):
110107
ret = get_files_matching_func('', '\\.py$')
111-
assert ret == set(['hooks.yaml', 'testing/test_symlink'])
108+
assert ret == {'hooks.yaml', 'testing/test_symlink'}
112109

113110

114111
def resolve_conflict():
@@ -124,12 +121,12 @@ def test_get_conflicted_files(in_merge_conflict):
124121
cmd_output('git', 'add', 'other_file')
125122

126123
ret = set(git.get_conflicted_files())
127-
assert ret == set(('conflict_file', 'other_file'))
124+
assert ret == {'conflict_file', 'other_file'}
128125

129126

130127
def test_get_conflicted_files_in_submodule(in_conflicting_submodule):
131128
resolve_conflict()
132-
assert set(git.get_conflicted_files()) == set(('conflict_file',))
129+
assert set(git.get_conflicted_files()) == {'conflict_file'}
133130

134131

135132
def test_get_conflicted_files_unstaged_files(in_merge_conflict):
@@ -142,7 +139,7 @@ def test_get_conflicted_files_unstaged_files(in_merge_conflict):
142139
bar_only_file.write('new contents!\n')
143140

144141
ret = set(git.get_conflicted_files())
145-
assert ret == set(('conflict_file',))
142+
assert ret == {'conflict_file'}
146143

147144

148145
MERGE_MSG = "Merge branch 'foo' into bar\n\nConflicts:\n\tconflict_file\n"

tests/repository_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def test_languages(tempdir_factory, store):
426426
path = make_repo(tempdir_factory, 'python_hooks_repo')
427427
config = make_config_from_repo(path)
428428
repo = Repository.create(config, store)
429-
assert repo.languages == set([('python', 'default')])
429+
assert repo.languages == {('python', 'default')}
430430

431431

432432
@pytest.mark.integration
@@ -435,7 +435,7 @@ def test_additional_dependencies(tempdir_factory, store):
435435
config = make_config_from_repo(path)
436436
config['hooks'][0]['additional_dependencies'] = ['pep8']
437437
repo = Repository.create(config, store)
438-
assert repo.additional_dependencies['python']['default'] == set(('pep8',))
438+
assert repo.additional_dependencies['python']['default'] == {'pep8'}
439439

440440

441441
@pytest.mark.integration

0 commit comments

Comments
 (0)