gemini-code-assist[bot] commented on code in PR #298:
URL: https://github.com/apache/tvm-ffi/pull/298#discussion_r2577756885


##########
tests/python/test_stl.py:
##########
@@ -31,23 +30,28 @@ def test_stl() -> None:
 
     mod: Module = tvm_ffi.load_module(output_lib_path)
 
-    assert list(mod.test_tuple([1, 2.5])) == [2.5, 1]
-    assert mod.test_vector(None) == None
-    assert list(mod.test_vector([[1, 2], [3, 4]])) == [3, 7]
-    assert mod.test_variant(1) == "int"
-    assert mod.test_variant(1.0) == "float"
-    assert list(mod.test_variant([1, 1.0])) == ["int", "float"]
-    assert dict(mod.test_map({"a": 1, "b": 2})) == {1: "a", 2: "b"}
-    assert dict(mod.test_map_2({"a": 1, "b": 2})) == {1: "a", 2: "b"}
-    assert mod.test_function(lambda: 0)() == 1
-    assert mod.test_function(lambda: 10)() == 11
-
-    with pytest.raises(TypeError):
-        mod.test_tuple([1.5, 2.5])
-    with pytest.raises(TypeError):
-        mod.test_function(lambda: 0)(100)
-    gc.collect()
-    del mod
+    def run_check(mod: Module) -> None:
+        # This sub function is needed to make sure all temp variables 
deallocated
+        # before module unload since some of these objects contains deleters 
in the library
+        # code. If the module is unloaded before the object is deleted, the 
deleter
+        # may call an invalid address.
+        assert list(mod.test_tuple([1, 2.5])) == [2.5, 1]
+        assert mod.test_vector(None) == None

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   According to PEP 8, comparisons to singletons like `None` should always be 
done with `is` or `is not`, never the equality operators. Using `is` is faster 
and safer as it checks for object identity.[^1]
   
   ```suggestion
           assert mod.test_vector(None) is None
   ```
   
   #### Style Guide References
   [^1]: PEP 8: Comparisons to singletons like None should always be done with 
`is` or `is not`, never the equality operators.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to