Skip to content

Commit 3c5ca52

Browse files
committed
Simplify _safer_popen_windows "if shell" logic
This fixes a static typing error reported by mypy. Using a separate variable, as I had done originally, does not seem to be clearer than rebinding the parameter, and in this case the code is simpler and can be checked by mypy without needing another explicit type annotation to be added. This fixes one mypy error. This also adds a comment to make clearer why the mapping passed in is copied when modifications are needed, rather than mutated.
1 parent 2212ac9 commit 3c5ca52

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

git/cmd.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,9 @@ def _safer_popen_windows(
257257
# When using a shell, the shell is the direct subprocess, so the variable must be
258258
# set in its environment, to affect its search behavior. (The "1" can be any value.)
259259
if shell:
260-
safer_env = {} if env is None else dict(env)
261-
safer_env["NoDefaultCurrentDirectoryInExePath"] = "1"
262-
else:
263-
safer_env = env
260+
# The original may be immutable or reused by the caller. Make changes in a copy.
261+
env = {} if env is None else dict(env)
262+
env["NoDefaultCurrentDirectoryInExePath"] = "1"
264263

265264
# When not using a shell, the current process does the search in a CreateProcessW
266265
# API call, so the variable must be set in our environment. With a shell, this is
@@ -273,7 +272,7 @@ def _safer_popen_windows(
273272
return Popen(
274273
command,
275274
shell=shell,
276-
env=safer_env,
275+
env=env,
277276
creationflags=creationflags,
278277
**kwargs,
279278
)

0 commit comments

Comments
 (0)