Since there are no primitive types in Python, you yourself must define what you consider primitive:
primitive = (int, str, bool, ...)
def is_primitive(thing):
return isinstance(thing, primitive)
But then, do you consider this primitive, too:
class MyStr(str):
...
?
If not, you could do this:
def is_primitive(thing):
return type(thing) in primitive
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…