I’m making a function which will accept either an Unicode string or a bytes (or bytearray) object. I want to make sure only those types get passed. I know I can check whether something is a string by doing isinstance(x, str), and I know I can write isinstance(x, bytes) or isinstance(x, bytearray).
Is there a more concise way to check the latter, i.e., is there a class from which both bytes and bytearray derive?
There is no common base class except for
object:Don’t check for the type. Let the user pass parameters of whatever type she desires. If the type does not have the required interface, your code will fail anyway.