diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2018-09-11 04:57:20 -0700 |
---|---|---|
committer | Jon Dufresne <jon.dufresne@gmail.com> | 2018-09-11 05:45:36 -0700 |
commit | 02fea029bfc5bfd64e43de9e810aef2dd3c8cb2c (patch) | |
tree | 8460d233e013fe774e8e9d5a2cc3e3ef2392a37d /sphinx/builders/html.py | |
parent | 844a3a5c226ff8891a1ce139f10ac92157c75da5 (diff) | |
download | sphinx-git-02fea029bfc5bfd64e43de9e810aef2dd3c8cb2c.tar.gz |
Prefer builtin open() over io.open() and codecs.open()
In Python3, the functions io.open() is an alias of the builtin open()
and codecs.open() is functionally equivalent. To reduce indirection,
number of imports, and number of patterns, always prefer the builtin.
https://docs.python.org/3/library/io.html#high-level-module-interface
> io.open()
>
> This is an alias for the builtin open() function.
Diffstat (limited to 'sphinx/builders/html.py')
-rw-r--r-- | sphinx/builders/html.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 3c08cc818..b4b570bdc 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -9,7 +9,6 @@ :license: BSD, see LICENSE for details. """ -import codecs import posixpath import re import sys @@ -959,9 +958,9 @@ class StandaloneHTMLBuilder(Builder): try: searchindexfn = path.join(self.outdir, self.searchindex_filename) if self.indexer_dumps_unicode: - f = codecs.open(searchindexfn, 'r', encoding='utf-8') # type: ignore + f = open(searchindexfn, 'r', encoding='utf-8') # type: ignore else: - f = open(searchindexfn, 'rb') # type: ignore + f = open(searchindexfn, 'rb') with f: self.indexer.load(f, self.indexer_format) except (IOError, OSError, ValueError): @@ -1140,7 +1139,8 @@ class StandaloneHTMLBuilder(Builder): # outfilename's path is in general different from self.outdir ensuredir(path.dirname(outfilename)) try: - with codecs.open(outfilename, 'w', ctx['encoding'], 'xmlcharrefreplace') as f: # type: ignore # NOQA + with open(outfilename, 'w', # type: ignore + encoding=ctx['encoding'], errors='xmlcharrefreplace') as f: f.write(output) except (IOError, OSError) as err: logger.warning(__("error writing file %s: %s"), outfilename, err) @@ -1177,9 +1177,9 @@ class StandaloneHTMLBuilder(Builder): # first write to a temporary file, so that if dumping fails, # the existing index won't be overwritten if self.indexer_dumps_unicode: - f = codecs.open(searchindexfn + '.tmp', 'w', encoding='utf-8') # type: ignore + f = open(searchindexfn + '.tmp', 'w', encoding='utf-8') # type: ignore else: - f = open(searchindexfn + '.tmp', 'wb') # type: ignore + f = open(searchindexfn + '.tmp', 'wb') with f: self.indexer.dump(f, self.indexer_format) movefile(searchindexfn + '.tmp', searchindexfn) @@ -1436,9 +1436,9 @@ class SerializingHTMLBuilder(StandaloneHTMLBuilder): def dump_context(self, context, filename): # type: (Dict, unicode) -> None if self.implementation_dumps_unicode: - f = codecs.open(filename, 'w', encoding='utf-8') # type: ignore + f = open(filename, 'w', encoding='utf-8') # type: ignore else: - f = open(filename, 'wb') # type: ignore + f = open(filename, 'wb') with f: self.implementation.dump(context, f, *self.additional_dump_args) |