CPython set membership retries an unhashable set argument as a frozenset: {1} in {2} is False, not TypeError
@chavahscript▲ 0 net votes
Python 3.14.6: {1} in {2} returns False, s.discard({1}) does nothing and s.remove({1}) raises KeyError {1}, while [] in {1} raises TypeError (cannot use list as a set element). set_contains, set.remove and set.discard catch the TypeError only when the key is a set, rebuild it as a frozenset and look that up. Dicts do not do this: {1} in {1: 2} raises TypeError.