Skip to contentSkip to conversation

vmbus_testing: fix wrong python syntax for integer value comparison

PATCH Applied Ani Sinha 2 participants 3 messages Jul 5, 2023 – Jul 23, 2023

Subsystems (2)
lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

PATCH 1/1 vmbus_testing: fix wrong python syntax for integer value comparison

It is incorrect in python to compare integer values using the "is" keyword. The "is" keyword in python is used to compare references to two objects, not their values. Newer version of python3 (version 3.8) throws a warning when such incorrect comparison is made. For value comparison, "==" should be used.

Fix this in the code and suppress the following warning:

/usr/sbin/vmbus_testing:167: SyntaxWarning: "is" with a literal. Did you mean "=="?

---
 tools/hv/vmbus_testing | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/hv/vmbus_testing +2 -2
index e7212903dd1d..4467979d8f69 100755
@@ -164,7 +164,7 @@ def recursive_file_lookup(path, file_map):
 def get_all_devices_test_status(file_map):
 
         for device in file_map:
-                if (get_test_state(locate_state(device, file_map)) is 1):
+                if (get_test_state(locate_state(device, file_map)) == 1):
                         print("Testing = ON for: {}"
                               .format(device.split("/")[5]))
                 else:
@@ -203,7 +203,7 @@ def write_test_files(path, value):
 def set_test_state(state_path, state_value, quiet):
 
         write_test_files(state_path, state_value)
-        if (get_test_state(state_path) is 1):
+        if (get_test_state(state_path) == 1):
                 if (not quiet):
                         print("Testing = ON for device: {}"
                               .format(state_path.split("/")[5]))
Signature · 1 line
2.39.1
author
#1 lore raw
Quoted 10 lines · Ani Sinha

It is incorrect in python to compare integer values using the "is" keyword. The "is" keyword in python is used to compare references to two objects, not their values. Newer version of python3 (version 3.8) throws a warning when such incorrect comparison is made. For value comparison, "==" should be used.

Quoted 3 lines

Fix this in the code and suppress the following warning:

/usr/sbin/vmbus_testing:167: SyntaxWarning: "is" with a literal. Did you mean "=="?

Ping …

Quoted 31 lines

---
tools/hv/vmbus_testing | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
tools/hv/vmbus_testing +0 -0
index e7212903dd1d..4467979d8f69 100755
@@ -164,7 +164,7 @@ def recursive_file_lookup(path, file_map):

def get_all_devices_test_status(file_map):

for device in file_map:

tools/hv/vmbus_testing +1 -1
-                if (get_test_state(locate_state(device, file_map)) is 1):
+                if (get_test_state(locate_state(device, file_map)) == 1):
                        print("Testing = ON for: {}"
                              .format(device.split("/")[5]))
                else:
@@ -203,7 +203,7 @@ def write_test_files(path, value):

def set_test_state(state_path, state_value, quiet):

write_test_files(state_path, state_value)

tools/hv/vmbus_testing +1 -1
-        if (get_test_state(state_path) is 1):
+        if (get_test_state(state_path) == 1):
                if (not quiet):
                        print("Testing = ON for device: {}"
                              .format(state_path.split("/")[5]))
Signature · 1 line
2.39.1
maintainer Applied
#2 lore raw
Quoted 10 lines · Ani Sinha
Quoted 10 lines · Ani Sinha

It is incorrect in python to compare integer values using the "is" keyword. The "is" keyword in python is used to compare references to two objects, not their values. Newer version of python3 (version 3.8) throws a warning when such incorrect comparison is made. For value comparison, "==" should be used.

Quoted 6 lines
Quoted 3 lines

Fix this in the code and suppress the following warning:

/usr/sbin/vmbus_testing:167: SyntaxWarning: "is" with a literal. Did you mean "=="?

Ping …

Applied to hyperv-fixes. Thanks.