diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-17 19:19:08 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-17 19:19:08 +0900 |
commit | 07b8748a079ad292858e5000b9f3c2ea2fefc6c2 (patch) | |
tree | 34ee50004832453074cd738d520075d5b180ff91 /sphinx/util/osutil.py | |
parent | 94de89e0d086dd9a37b2089d112863b82afe7a61 (diff) | |
parent | e5bf235ba04707ff8aff33dd073bca9f9414b8fc (diff) | |
download | sphinx-git-07b8748a079ad292858e5000b9f3c2ea2fefc6c2.tar.gz |
Merge pull request #5804 from jdufresne/file-avoid-str
Remove unnecessary bytes/str type check in FileAvoidWrite.write()
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r-- | sphinx/util/osutil.py | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 74972da0c..c8088b384 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -17,11 +17,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: @@ -237,17 +235,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 @@ -258,23 +252,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): |