From 0248d55a217deeadd4dec6054d7cc12be1e40c25 Mon Sep 17 00:00:00 2001 From: Jason Pruitt Date: Thu, 5 Feb 2026 10:37:57 -0500 Subject: [PATCH] Remove try except for variable checking in favor of string.isidentifier() --- labscript/labscript.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/labscript/labscript.py b/labscript/labscript.py index 6e1d23f..db6fefd 100644 --- a/labscript/labscript.py +++ b/labscript/labscript.py @@ -718,13 +718,9 @@ def load_globals(hdf5_filename): raise LabscriptError('Error whilst parsing globals from %s. \'%s\''%(hdf5_filename,name) + ' is a reserved Python keyword.' + ' Please choose a different variable name.') - try: - assert '.' not in name - exec(name + ' = 0') - exec('del ' + name ) - except: - raise LabscriptError('ERROR whilst parsing globals from %s. \'%s\''%(hdf5_filename,name) + - 'is not a valid Python variable name.' + + if not name.isidentifier(): + raise LabscriptError('Error whilst parsing globals from %s. \'%s\''%(hdf5_filename,name) + + ' is not a valid Python variable name.' + ' Please choose a different variable name.') # Workaround for the fact that numpy.bool_ objects dont