def is_subclassable(c): "Magic expression provided by Daniel Urban" return c.__flags__ & (1 << 10) # try: exec(); except: TypeError; works for built-ins # but would be much tricker for types classes print ("Among named builtin classes, these cannot be subclassed:") for c in (bool, bytearray, bytes, complex, dict, enumerate, filter, float, frozenset, int, list, map, memoryview, object, range, set, slice, str, tuple, type, zip): if not is_subclassable(c): print(c.__name__, end=', ') print() print("Among types classes, these can be subclassed:") import types d = vars(types) for key in d: if key[0].isupper() and is_subclassable(d[key]): print(key, end=', ') print()