From bfdb3bc6369af7564d379615fee84ad1b6aca9b2 Mon Sep 17 00:00:00 2001 From: "systems-assistant[bot]" <221163467+systems-assistant[bot]@users.noreply.github.com> Date: Wed, 10 Sep 2025 14:50:32 -0500 Subject: [PATCH] fix(python): fix comparison to None (#211) from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations): > Comparisons to singletons like None should always be done with is or is not, never the equality operators. Co-authored-by: Eisuke Kawashima --- projects/rocm-smi-lib/python_smi_tools/rocm_smi.py | 12 ++++++------ .../rocm-smi-lib/python_smi_tools/rsmiBindings.py.in | 2 +- .../python_smi_tools/rsmiBindingsInit.py.in | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py index 253928bdbe..131aeaca88 100755 --- a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py +++ b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py @@ -476,7 +476,7 @@ def getAllocatedMemoryPercent(device): mem_use_pct = 0 if vram_used is None: return allocated_memory_vram - if vram_used != None and vram_total != None and float(vram_total) != 0: + if vram_used is not None and vram_total is not None and float(vram_total) != 0: # take floor of result (round down to nearest integer) mem_use_pct = (100 * (float(vram_used) / float(vram_total))) // 1 allocated_memory_vram['value'] = mem_use_pct @@ -531,7 +531,7 @@ def getProcessName(pid): except subprocess.CalledProcessError as e: pName = 'UNKNOWN' - if pName == None: + if pName is None: pName = 'UNKNOWN' # Remove the substrings surrounding from process name (b' and \n') @@ -2382,7 +2382,7 @@ def getCoarseGrainUtil(device, typeName=None): """ timestamp = c_uint64(0) - if typeName != None: + if typeName is not None: try: i = utilization_counter_name.index(typeName) @@ -3329,7 +3329,7 @@ def showWeightTopology(deviceList): for gpu2 in deviceList: if (gpu1 == gpu2): printTableRow('%-12s', '0') - elif (gpu_links_weight[gpu1][gpu2] == None): + elif (gpu_links_weight[gpu1][gpu2] is None): printTableRow('%-12s', 'N/A') else: printTableRow('%-12s', gpu_links_weight[gpu1][gpu2].value) @@ -3375,7 +3375,7 @@ def showHopsTopology(deviceList): for gpu2 in deviceList: if (gpu1 == gpu2): printTableRow('%-12s', '0') - elif (gpu_links_hops[gpu1][gpu2] == None): + elif (gpu_links_hops[gpu1][gpu2] is None): printTableRow('%-12s', 'N/A') else: printTableRow('%-12s', gpu_links_hops[gpu1][gpu2].value) @@ -4612,7 +4612,7 @@ if __name__ == '__main__': showPcieReplayCount(deviceList) if args.showserial: showSerialNumber(deviceList) - if args.showpids != None: + if args.showpids is not None: showPids(args.showpids) if args.showpidgpus or str(args.showpidgpus) == '[]': showGpusByPid(args.showpidgpus) diff --git a/projects/rocm-smi-lib/python_smi_tools/rsmiBindings.py.in b/projects/rocm-smi-lib/python_smi_tools/rsmiBindings.py.in index 18a8535867..aaed22835e 100644 --- a/projects/rocm-smi-lib/python_smi_tools/rsmiBindings.py.in +++ b/projects/rocm-smi-lib/python_smi_tools/rsmiBindings.py.in @@ -23,7 +23,7 @@ def initRsmiBindings(silent=False): print(args) rocm_smi_lib_path = os.getenv('ROCM_SMI_LIB_PATH') - if (rocm_smi_lib_path != None): + if (rocm_smi_lib_path is not None): path_librocm = rocm_smi_lib_path else: path_librocm = os.path.dirname(os.path.realpath(__file__)) + '/../../@CMAKE_INSTALL_LIBDIR@/librocm_smi64.so.@VERSION_MAJOR@' diff --git a/projects/rocm-smi-lib/python_smi_tools/rsmiBindingsInit.py.in b/projects/rocm-smi-lib/python_smi_tools/rsmiBindingsInit.py.in index 12b92186ad..7c75c4af87 100644 --- a/projects/rocm-smi-lib/python_smi_tools/rsmiBindingsInit.py.in +++ b/projects/rocm-smi-lib/python_smi_tools/rsmiBindingsInit.py.in @@ -23,7 +23,7 @@ def initRsmiBindings(silent=False): print(args) rocm_smi_lib_path = os.getenv('ROCM_SMI_LIB_PATH') - if (rocm_smi_lib_path != None): + if (rocm_smi_lib_path is not None): path_librocm = rocm_smi_lib_path else: path_librocm = os.path.dirname(os.path.realpath(__file__)) + '/../../@CMAKE_INSTALL_LIBDIR@/librocm_smi64.so.@VERSION_MAJOR@'