From e818f8219a21273bbe3633a61e6a9cbef6a9b3f1 Mon Sep 17 00:00:00 2001 From: R0CKSTAR Date: Sat, 7 Mar 2026 08:15:21 +0800 Subject: [PATCH] Fix none-comparison (E711) warnings (#19745) Signed-off-by: Xiaodong Ye --- python/sglang/eval/llama3_eval.py | 2 +- python/sglang/multimodal_gen/third_party/pynvml.py | 10 +++++----- python/sglang/srt/mem_cache/memory_pool.py | 2 +- .../storage/nixl/test_hicache_nixl_storage.py | 4 ++-- python/sglang/srt/utils/common.py | 10 +++++----- python/sglang/srt/utils/rpd_utils.py | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/python/sglang/eval/llama3_eval.py b/python/sglang/eval/llama3_eval.py index 253cdf275..4a3c736de 100644 --- a/python/sglang/eval/llama3_eval.py +++ b/python/sglang/eval/llama3_eval.py @@ -86,7 +86,7 @@ class CustomAsyncHTTPXClient(httpx.AsyncClient): def get_client(provider): if provider not in "b10": - if os.getenv("OPENAI_API_KEY") == None: + if os.getenv("OPENAI_API_KEY") is None: os.environ["OPENAI_API_KEY"] = "EMPTY" return { "oai": AsyncOpenAI(base_url="http://127.0.0.1:8000/v1/"), diff --git a/python/sglang/multimodal_gen/third_party/pynvml.py b/python/sglang/multimodal_gen/third_party/pynvml.py index 24d0a714c..52467b025 100644 --- a/python/sglang/multimodal_gen/third_party/pynvml.py +++ b/python/sglang/multimodal_gen/third_party/pynvml.py @@ -1321,7 +1321,7 @@ def _nvmlGetFunctionPointer(name): libLoadLock.acquire() try: # ensure library was loaded - if nvmlLib == None: + if nvmlLib is None: raise NVMLError(NVML_ERROR_UNINITIALIZED) try: _nvmlGetFunctionPointer_cache[name] = getattr(nvmlLib, name) @@ -1629,7 +1629,7 @@ class nvmlClkMonStatus_t(Structure): # On Windows with the WDDM driver, usedGpuMemory is reported as None # Code that processes this structure should check for None, I.E. # -# if (info.usedGpuMemory == None): +# if (info.usedGpuMemory is None): # # TODO handle the error # pass # else: @@ -2870,13 +2870,13 @@ def _LoadNvmlLibrary(): """ global nvmlLib - if nvmlLib == None: + if nvmlLib is None: # lock to ensure only one caller loads the library libLoadLock.acquire() try: # ensure the library still isn't loaded - if nvmlLib == None: + if nvmlLib is None: try: if sys.platform[:3] == "win": # cdecl calling convention @@ -2902,7 +2902,7 @@ def _LoadNvmlLibrary(): nvmlLib = CDLL("libnvidia-ml.so.1") except OSError as ose: _nvmlCheckReturn(NVML_ERROR_LIBRARY_NOT_FOUND) - if nvmlLib == None: + if nvmlLib is None: _nvmlCheckReturn(NVML_ERROR_LIBRARY_NOT_FOUND) finally: # lock is always freed diff --git a/python/sglang/srt/mem_cache/memory_pool.py b/python/sglang/srt/mem_cache/memory_pool.py index 6d7fed4b7..16b1410c3 100644 --- a/python/sglang/srt/mem_cache/memory_pool.py +++ b/python/sglang/srt/mem_cache/memory_pool.py @@ -380,7 +380,7 @@ class MambaPool: def fork_from(self, src_index: torch.Tensor) -> Optional[torch.Tensor]: dst_index = self.alloc(1) - if dst_index == None: + if dst_index is None: return None self.copy_from(src_index, dst_index) return dst_index diff --git a/python/sglang/srt/mem_cache/storage/nixl/test_hicache_nixl_storage.py b/python/sglang/srt/mem_cache/storage/nixl/test_hicache_nixl_storage.py index aea004a6d..ad1796f0a 100755 --- a/python/sglang/srt/mem_cache/storage/nixl/test_hicache_nixl_storage.py +++ b/python/sglang/srt/mem_cache/storage/nixl/test_hicache_nixl_storage.py @@ -124,7 +124,7 @@ class TestNixlUnified(unittest.TestCase): # Test get retrieved2 = self.hicache.get(key, dst_addr, dst_len) - self.assertTrue(retrieved2 == None) + self.assertTrue(retrieved2 is None) self.verify_tensors_equal(value, dst_tensor2) def test_batch_set_get(self): @@ -159,7 +159,7 @@ class TestNixlUnified(unittest.TestCase): # Test batch get retrieved2 = self.hicache.batch_get(keys, dst_addrs, dst_lens) - self.assertTrue(all(ret == None for ret in retrieved2)) + self.assertTrue(all(ret is None for ret in retrieved2)) self.verify_tensor_lists_equal(values, dst_tensors2) def test_mixed_operations(self): diff --git a/python/sglang/srt/utils/common.py b/python/sglang/srt/utils/common.py index 5afbcd66a..2af599c02 100644 --- a/python/sglang/srt/utils/common.py +++ b/python/sglang/srt/utils/common.py @@ -2065,12 +2065,12 @@ def get_device(device_id: Optional[int] = None) -> str: return "cuda:{}".format(device_id) if hasattr(torch, "xpu") and torch.xpu.is_available(): - if device_id == None: + if device_id is None: return "xpu" return "xpu:{}".format(device_id) if is_npu(): - if device_id == None: + if device_id is None: return "npu" return "npu:{}".format(device_id) @@ -2079,16 +2079,16 @@ def get_device(device_id: Optional[int] = None) -> str: import habana_frameworks.torch.hpu # noqa: F401 if torch.hpu.is_available(): - if device_id == None: + if device_id is None: return "hpu" return "hpu:{}".format(device_id) - except ImportError as e: + except ImportError: raise ImportError( "Habana frameworks detected, but failed to import 'habana_frameworks.torch.hpu'." ) if is_musa(): - if device_id == None: + if device_id is None: return "musa" return "musa:{}".format(device_id) diff --git a/python/sglang/srt/utils/rpd_utils.py b/python/sglang/srt/utils/rpd_utils.py index 18b62d40f..3f4808d55 100644 --- a/python/sglang/srt/utils/rpd_utils.py +++ b/python/sglang/srt/utils/rpd_utils.py @@ -68,7 +68,7 @@ def rpd_to_chrome_trace( rangeStringMonitor = "" min_time = connection.execute("select MIN(start) from rocpd_api;").fetchall()[0][0] max_time = connection.execute("select MAX(end) from rocpd_api;").fetchall()[0][0] - if min_time == None: + if min_time is None: raise Exception("Trace file is empty.") print("Timestamps:")