Checking That Two Args Are Of Same Type (Posting On Python-List Prohibi
From
Lawrence D'Oliveiro@21:1/5 to
All on Sun Jun 23 01:17:35 2024
Consider a function taking two args “a” and “b”, which can be of str, bytes or bytearray type, just so long as both are of the same type.
One easy way to test this is
if sum(isinstance(a, t) and isinstance(b, t) for t in (str, bytes, bytearray)) != 1 :
raise TypeError("args must both be str or bytes")
#end if
Actually, both “and’ and “or” will work.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)