I have code that expects str but will handle the case of being passed bytes in the following way:
if isinstance(data, bytes):
data
The test if isinstance(data, bytes) or if type(data) == bytes, etc. doesn't work in Python 2, where a simple ASCII string passes the test of ! Because I use both Python 2 and Python 3, in order to overcome this I do the following check:
if str(type(data)).find("bytes") != -1: print("It's ")
It's a little ugly, but it does the job the question asks and it always works, in the simplest way.