Lawrence D'Oliveiro
2024-06-23 01:17:35 UTC
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.
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.