From: Joseph Sutton Date: Wed, 10 Jan 2024 22:23:53 +0000 (+1300) Subject: s4:scripting: Ensure generated error definition files are closed after use X-Git-Tag: talloc-2.4.2~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e82159d0f65087af861027bf35544a1e26454ab;p=thirdparty%2Fsamba.git s4:scripting: Ensure generated error definition files are closed after use This helps to avoid warnings like this one: /data/samba/source4/scripting/bin/gen_hresult.py:178: ResourceWarning: unclosed file <_io.TextIOWrapper name='/data/samba/bin/default/libcli/util/hresult.c' mode='w' encoding='UTF-8'> main() ResourceWarning: Enable tracemalloc to get the object allocation traceback Signed-off-by: Joseph Sutton Reviewed-by: Douglas Bagnall --- diff --git a/source4/scripting/bin/gen_hresult.py b/source4/scripting/bin/gen_hresult.py index b302d2d3dc8..03d25c820ff 100755 --- a/source4/scripting/bin/gen_hresult.py +++ b/source4/scripting/bin/gen_hresult.py @@ -168,11 +168,10 @@ def main (): with open(input_file1) as file_contents: errors = parseErrorDescriptions(file_contents, False, transformErrorName) - out_file = open(headerfile_name,"w") - generateHeaderFile(out_file, errors) - out_file.close() - out_file = open(sourcefile_name,"w") - generateSourceFile(out_file, errors) + with open(headerfile_name,"w") as out_file: + generateHeaderFile(out_file, errors) + with open(sourcefile_name,"w") as out_file: + generateSourceFile(out_file, errors) if __name__ == '__main__':