mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
FIX: Use context managers and explicit encoding
This commit is contained in:
parent
8e780a5a10
commit
8bd28f6af1
@ -137,9 +137,7 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
||||
|
||||
new_files.append(fn)
|
||||
|
||||
f = open(fn, 'w')
|
||||
|
||||
try:
|
||||
with open(fn, 'w') as f:
|
||||
doc = get_documenter(obj, parent)
|
||||
|
||||
if template_name is not None:
|
||||
@ -201,8 +199,6 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
||||
|
||||
rendered = template.render(**ns)
|
||||
f.write(rendered)
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
# descend recursively to new files
|
||||
if new_files:
|
||||
@ -221,12 +217,13 @@ def find_autosummary_in_files(filenames):
|
||||
"""
|
||||
documented = []
|
||||
for filename in filenames:
|
||||
f = open(filename, 'r')
|
||||
lines = f.read().splitlines()
|
||||
documented.extend(find_autosummary_in_lines(lines, filename=filename))
|
||||
f.close()
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
lines = f.read().splitlines()
|
||||
documented.extend(find_autosummary_in_lines(lines,
|
||||
filename=filename))
|
||||
return documented
|
||||
|
||||
|
||||
def find_autosummary_in_docstring(name, module=None, filename=None):
|
||||
"""Find out what items are documented in the given object's docstring.
|
||||
|
||||
@ -245,6 +242,7 @@ def find_autosummary_in_docstring(name, module=None, filename=None):
|
||||
"statement and it might call sys.exit()." % name)
|
||||
return []
|
||||
|
||||
|
||||
def find_autosummary_in_lines(lines, module=None, filename=None):
|
||||
"""Find out what items appear in autosummary:: directives in the
|
||||
given lines.
|
||||
|
Loading…
Reference in New Issue
Block a user