Skip to content

Commit 39a8ef4

Browse files
committed
Simplify conditional encoding in install_scripts and easy_install
1 parent f35f912 commit 39a8ef4

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

setuptools/command/easy_install.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -874,12 +874,8 @@ def write_script(self, script_name, contents, mode="t", blockers=()):
874874
if os.path.exists(target):
875875
os.unlink(target)
876876

877-
if "b" not in mode and isinstance(contents, str):
878-
kw = {"encoding": "utf-8"}
879-
else:
880-
kw = {}
881-
882-
with open(target, "w" + mode, **kw) as f:
877+
encoding = None if "b" in mode else "utf-8"
878+
with open(target, "w" + mode, encoding=encoding) as f:
883879
f.write(contents)
884880
chmod(target, 0o777 - mask)
885881

setuptools/command/install_scripts.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,10 @@ def write_script(self, script_name, contents, mode="t", *ignored):
5757
target = os.path.join(self.install_dir, script_name)
5858
self.outfiles.append(target)
5959

60-
if "b" not in mode and isinstance(contents, str):
61-
kw = {"encoding": "utf-8"}
62-
else:
63-
kw = {}
64-
60+
encoding = None if "b" in mode else "utf-8"
6561
mask = current_umask()
6662
if not self.dry_run:
6763
ensure_directory(target)
68-
with open(target, "w" + mode, **kw) as f:
64+
with open(target, "w" + mode, encoding=encoding) as f:
6965
f.write(contents)
7066
chmod(target, 0o777 - mask)

0 commit comments

Comments
 (0)