Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: net: fix wrong boolean evaluation in __exit__

The __exit__ method receives ex_type as the exception class when an
exception occurs. The previous code used implicit boolean evaluation:

terminate = self.terminate or (self._exit_wait and ex_type)
^^^^^^^^^^^

In Python, the and operator can be used with non-boolean values, but it
does not always return a boolean result.

This is probably not what we want, because 'self._exit_wait and ex_type'
could return the actual ex_type value (the exception class) rather than
a boolean True when an exception occurs.

Use explicit `ex_type is not None` check to properly evaluate whether
an exception occurred, returning a boolean result.

Reviewed-by: Nimrod Oren <noren@nvidia.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
Link: https://patch.msgid.link/20260125105524.773993-1-gal@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Gal Pressman and committed by
Jakub Kicinski
a84a1fe0 3ccf393c

+1 -1
+1 -1
tools/testing/selftests/net/lib/py/utils.py
··· 160 160 161 161 def __exit__(self, ex_type, ex_value, ex_tb): 162 162 # Force termination on exception 163 - terminate = self.terminate or (self._exit_wait and ex_type) 163 + terminate = self.terminate or (self._exit_wait and ex_type is not None) 164 164 return self.process(terminate=terminate, fail=self.check_fail) 165 165 166 166