Skip to content

Commit 5779f93

Browse files
committed
keyword only arguments in some places
1 parent 34c3a15 commit 5779f93

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

pre_commit/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ def _setdefault_kwargs(kwargs: Dict[str, Any]) -> None:
108108

109109
def cmd_output_b(
110110
*cmd: str,
111+
retcode: Optional[int] = 0,
111112
**kwargs: Any,
112113
) -> Tuple[int, bytes, Optional[bytes]]:
113-
retcode = kwargs.pop('retcode', 0)
114114
_setdefault_kwargs(kwargs)
115115

116116
try:
@@ -176,9 +176,10 @@ def __exit__(
176176

177177
def cmd_output_p(
178178
*cmd: str,
179+
retcode: Optional[int] = 0,
179180
**kwargs: Any,
180181
) -> Tuple[int, bytes, Optional[bytes]]:
181-
assert kwargs.pop('retcode') is None
182+
assert retcode is None
182183
assert kwargs['stderr'] == subprocess.STDOUT, kwargs['stderr']
183184
_setdefault_kwargs(kwargs)
184185

pre_commit/xargs.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,17 @@ def _thread_mapper(maxsize: int) -> Generator[
117117
def xargs(
118118
cmd: Tuple[str, ...],
119119
varargs: Sequence[str],
120+
*,
121+
color: bool = False,
122+
target_concurrency: int = 1,
123+
_max_length: int = _get_platform_max_length(),
120124
**kwargs: Any,
121125
) -> Tuple[int, bytes]:
122126
"""A simplified implementation of xargs.
123127
124128
color: Make a pty if on a platform that supports it
125129
target_concurrency: Target number of partitions to run concurrently
126130
"""
127-
color = kwargs.pop('color', False)
128-
target_concurrency = kwargs.pop('target_concurrency', 1)
129-
max_length = kwargs.pop('_max_length', _get_platform_max_length())
130131
cmd_fn = cmd_output_p if color else cmd_output_b
131132
retcode = 0
132133
stdout = b''
@@ -136,7 +137,7 @@ def xargs(
136137
except parse_shebang.ExecutableNotFoundError as e:
137138
return e.to_output()[:2]
138139

139-
partitions = partition(cmd, varargs, target_concurrency, max_length)
140+
partitions = partition(cmd, varargs, target_concurrency, _max_length)
140141

141142
def run_cmd_partition(
142143
run_cmd: Tuple[str, ...],

testing/util.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ def get_resource_path(path):
1818
return os.path.join(TESTING_DIR, 'resources', path)
1919

2020

21-
def cmd_output_mocked_pre_commit_home(*args, **kwargs):
22-
# keyword-only argument
23-
tempdir_factory = kwargs.pop('tempdir_factory')
24-
pre_commit_home = kwargs.pop('pre_commit_home', tempdir_factory.get())
21+
def cmd_output_mocked_pre_commit_home(
22+
*args, tempdir_factory, pre_commit_home=None, env=None, **kwargs,
23+
):
24+
if pre_commit_home is None:
25+
pre_commit_home = tempdir_factory.get()
26+
env = env if env is not None else os.environ
2527
kwargs.setdefault('stderr', subprocess.STDOUT)
2628
# Don't want to write to the home directory
27-
env = dict(kwargs.pop('env', os.environ), PRE_COMMIT_HOME=pre_commit_home)
29+
env = dict(env, PRE_COMMIT_HOME=pre_commit_home)
2830
ret, out, _ = cmd_output(*args, env=env, **kwargs)
2931
return ret, out.replace('\r\n', '\n'), None
3032

@@ -123,9 +125,7 @@ def cwd(path):
123125
os.chdir(original_cwd)
124126

125127

126-
def git_commit(*args, **kwargs):
127-
fn = kwargs.pop('fn', cmd_output)
128-
msg = kwargs.pop('msg', 'commit!')
128+
def git_commit(*args, fn=cmd_output, msg='commit!', **kwargs):
129129
kwargs.setdefault('stderr', subprocess.STDOUT)
130130

131131
cmd = ('git', 'commit', '--allow-empty', '--no-gpg-sign', '-a') + args

tests/envcontext_test.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
from pre_commit.envcontext import Var
99

1010

11-
def _test(**kwargs):
12-
before = kwargs.pop('before')
13-
patch = kwargs.pop('patch')
14-
expected = kwargs.pop('expected')
15-
assert not kwargs
16-
11+
def _test(*, before, patch, expected):
1712
env = before.copy()
1813
with envcontext(patch, _env=env):
1914
assert env == expected

0 commit comments

Comments
 (0)