From 895fa6f83ca71a41999f949a4b094b32a817261a Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sun, 2 May 2021 02:36:44 +0200 Subject: [PATCH] [pylint] Fix referencing undefined variable 'shutil' Let's just use the scope limited TemporaryDirectory() instead, so the temporary directory will be removed by Python automatically. pySim/filesystem.py:679:16: E0602: Undefined variable 'shutil' (undefined-variable) Change-Id: I4ea833fd79f4342c33899124379be509ba1e35ed --- pySim/filesystem.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pySim/filesystem.py b/pySim/filesystem.py index dec521e4..edfe85dc 100644 --- a/pySim/filesystem.py +++ b/pySim/filesystem.py @@ -659,8 +659,7 @@ class LinFixedEF(CardEF): def do_edit_record_decoded(self, opts): """Edit the JSON representation of one record in an editor.""" (orig_json, sw) = self._cmd.rs.read_record_dec(opts.record_nr) - dirname = tempfile.mkdtemp(prefix='pysim_') - try: + with tempfile.TemporaryDirectory(prefix='pysim_') as dirname: filename = '%s/file' % dirname # write existing data as JSON to file with open(filename, 'w') as text_file: @@ -675,8 +674,6 @@ class LinFixedEF(CardEF): (data, sw) = self._cmd.rs.update_record_dec(opts.record_nr, edited_json) if data: self._cmd.poutput_json(data) - finally: - shutil.rmtree(dirname) def __init__(self, fid:str, sfid:str=None, name:str=None, desc:str=None,