From 9c5b3401ff4da30a78b3a4b26d8062462d96b8fe Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 16 Jul 2019 17:07:28 +0200 Subject: [PATCH] Close file after using it (#59000) --- lib/ansible/parsing/plugin_docs.py | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/ansible/parsing/plugin_docs.py b/lib/ansible/parsing/plugin_docs.py index ac3f90531aa..73945306c24 100644 --- a/lib/ansible/parsing/plugin_docs.py +++ b/lib/ansible/parsing/plugin_docs.py @@ -90,30 +90,30 @@ def read_docstub(filename): operations like ansible-doc -l. """ - t_module_data = open(filename, 'r') in_documentation = False capturing = False indent_detection = '' doc_stub = [] - for line in t_module_data: - if in_documentation: - # start capturing the stub until indentation returns - if capturing and line.startswith(indent_detection): - doc_stub.append(line) + with open(filename, 'r') as t_module_data: + for line in t_module_data: + if in_documentation: + # start capturing the stub until indentation returns + if capturing and line.startswith(indent_detection): + doc_stub.append(line) - elif capturing and not line.startswith(indent_detection): - break + elif capturing and not line.startswith(indent_detection): + break - elif line.lstrip().startswith('short_description:'): - capturing = True - # Detect that the short_description continues on the next line if it's indented more - # than short_description itself. - indent_detection = ' ' * (len(line) - len(line.lstrip()) + 1) - doc_stub.append(line) + elif line.lstrip().startswith('short_description:'): + capturing = True + # Detect that the short_description continues on the next line if it's indented more + # than short_description itself. + indent_detection = ' ' * (len(line) - len(line.lstrip()) + 1) + doc_stub.append(line) - elif line.startswith('DOCUMENTATION') and '=' in line: - in_documentation = True + elif line.startswith('DOCUMENTATION') and '=' in line: + in_documentation = True short_description = r''.join(doc_stub).strip().rstrip('.') data = AnsibleLoader(short_description, file_name=filename).get_single_data()