From e5bf235ba04707ff8aff33dd073bca9f9414b8fc Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 15 Dec 2018 17:45:42 -0800 Subject: [PATCH] Remove unnecessary bytes/str type check in FileAvoidWrite.write() All calls to FileAvoidWrite.write() always pass a text string. Additionally, the type signature only allows type str. --- sphinx/util/osutil.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 8d179d210..05cd9e8df 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -18,11 +18,9 @@ import shutil import sys import time import warnings -from io import BytesIO, StringIO +from io import StringIO from os import path -from six import text_type - from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning if False: @@ -238,17 +236,13 @@ class FileAvoidWrite: def __init__(self, path): # type: (str) -> None self._path = path - self._io = None # type: Union[StringIO, BytesIO] + self._io = None # type: StringIO def write(self, data): - # type: (Union[str, str]) -> None + # type: (str) -> None if not self._io: - if isinstance(data, text_type): - self._io = StringIO() - else: - self._io = BytesIO() - - self._io.write(data) # type: ignore + self._io = StringIO() + self._io.write(data) def close(self): # type: () -> None @@ -259,23 +253,15 @@ class FileAvoidWrite: buf = self.getvalue() self._io.close() - r_mode = 'r' - w_mode = 'w' - if isinstance(self._io, BytesIO): - r_mode = 'rb' - w_mode = 'wb' - - old_content = None - try: - with open(self._path, r_mode) as old_f: + with open(self._path) as old_f: old_content = old_f.read() if old_content == buf: return except IOError: pass - with open(self._path, w_mode) as f: + with open(self._path, 'w') as f: f.write(buf) def __enter__(self):