No need for explicit string conversion

This commit is contained in:
Fabien Castan 2025-04-14 11:09:12 +02:00
parent 51b04bc077
commit 4e1182c3dc
5 changed files with 16 additions and 16 deletions

View file

@ -91,7 +91,7 @@ def loadPlugins(folder, packageName, classType):
if importPlugin:
pluginTypes.extend(plugins)
except Exception as e:
errors.append(f' * {pluginName}: {str(e)}')
errors.append(f' * {pluginName}: {e}')
if errors:
logging.warning('== The following "{package}" plugins could not be loaded ==\n'

View file

@ -737,7 +737,7 @@ class Graph(BaseObject):
try:
self.addEdge(self.attribute(srcName), self.attribute(dstName))
except (KeyError, ValueError) as e:
logging.warning(f"Failed to restore edge {srcName} -> {dstName}: {str(e)}")
logging.warning(f"Failed to restore edge {srcName} -> {dstName}: {e}")
def upgradeAllNodes(self):
""" Upgrade all upgradable CompatibilityNode instances in the graph. """

View file

@ -84,7 +84,7 @@ class ComputerStatistics:
self._addKV('ioCounters', psutil.disk_io_counters())
self.updateGpu()
except Exception as e:
logging.debug(f'Failed to get statistics: "{str(e)}".')
logging.debug(f'Failed to get statistics: "{e}".')
def updateGpu(self):
if not self.nvidia_smi:
@ -99,38 +99,38 @@ class ComputerStatistics:
try:
self.gpuName = gpuTree.find('product_name').text
except Exception as e:
logging.debug(f'Failed to get gpuName: "{str(e)}".')
logging.debug(f'Failed to get gpuName: "{e}".')
pass
try:
gpuMemoryUsed = gpuTree.find('fb_memory_usage').find('used').text.split(" ")[0]
self._addKV('gpuMemoryUsed', gpuMemoryUsed)
except Exception as e:
logging.debug(f'Failed to get gpuMemoryUsed: "{str(e)}".')
logging.debug(f'Failed to get gpuMemoryUsed: "{e}".')
pass
try:
self.gpuMemoryTotal = gpuTree.find('fb_memory_usage').find('total').text.split(" ")[0]
except Exception as e:
logging.debug(f'Failed to get gpuMemoryTotal: "{str(e)}".')
logging.debug(f'Failed to get gpuMemoryTotal: "{e}".')
pass
try:
gpuUsed = gpuTree.find('utilization').find('gpu_util').text.split(" ")[0]
self._addKV('gpuUsed', gpuUsed)
except Exception as e:
logging.debug(f'Failed to get gpuUsed: "{str(e)}".')
logging.debug(f'Failed to get gpuUsed: "{e}".')
pass
try:
gpuTemperature = gpuTree.find('temperature').find('gpu_temp').text.split(" ")[0]
self._addKV('gpuTemperature', gpuTemperature)
except Exception as e:
logging.debug(f'Failed to get gpuTemperature: "{str(e)}".')
logging.debug(f'Failed to get gpuTemperature: "{e}".')
pass
except subprocess.TimeoutExpired as e:
logging.debug(f'Timeout when retrieving information from nvidia_smi: "{str(e)}".')
logging.debug(f'Timeout when retrieving information from nvidia_smi: "{e}".')
p.kill()
outs, errs = p.communicate()
return
except Exception as e:
logging.debug(f'Failed to get information from nvidia_smi: "{str(e)}".')
logging.debug(f'Failed to get information from nvidia_smi: "{e}".')
return
def toDict(self):
@ -270,15 +270,15 @@ class Statistics:
try:
self.computer.fromDict(d.get('computer', {}))
except Exception as e:
logging.debug(f'Failed while loading statistics: computer: "{str(e)}".')
logging.debug(f'Failed while loading statistics: computer: "{e}".')
try:
self.process.fromDict(d.get('process', {}))
except Exception as e:
logging.debug(f'Failed while loading statistics: process: "{str(e)}".')
logging.debug(f'Failed while loading statistics: process: "{e}".')
try:
self.times = d.get('times', [])
except Exception as e:
logging.debug(f'Failed while loading statistics: times: "{str(e)}".')
logging.debug(f'Failed while loading statistics: times: "{e}".')
bytesPerGiga = 1024. * 1024. * 1024.

View file

@ -77,7 +77,7 @@ class CsvData(QObject):
for idx, value in enumerate(elt):
dataList[idx].appendValue(value)
except Exception as e:
logging.error(f"CsvData: Failed to load file: {self._filepath}\n{str(e)}")
logging.error(f"CsvData: Failed to load file: {self._filepath}\n{e}")
return dataList

View file

@ -225,7 +225,7 @@ class ViewpointWrapper(QObject):
# When the viewpoint attribute has already been deleted, metadata.value becomes a PySide property (whereas a string is expected)
self._metadata = json.loads(self._viewpoint.metadata.value) if isinstance(self._viewpoint.metadata.value, str) and self._viewpoint.metadata.value else None
except Exception as e:
logging.warning(f"Failed to parse Viewpoint metadata: '{str(e)}', '{str(self._viewpoint.metadata.value)}'")
logging.warning(f"Failed to parse Viewpoint metadata: '{e}', '{str(self._viewpoint.metadata.value)}'")
self._metadata = {}
if not self._metadata:
self._metadata = {}
@ -974,7 +974,7 @@ class Reconstruction(UIGraph):
# Retrieve the list of updated viewpoints and intrinsics
views, intrinsics = cameraInitCopy.nodeDesc.buildIntrinsics(cameraInitCopy, additionalViews)
except Exception as e:
logging.error(f"Error while building intrinsics: {str(e)}")
logging.error(f"Error while building intrinsics: {e}")
raise
finally:
# Delete the duplicate