logoalt Hacker News

chriswarbolast Thursday at 1:52 PM1 replyview on HN

> Theoretically, could `set` be a subclass of `frozenset` (and `dict` of `frozendict`)?

At one extreme: sure, anything can be made a subclass of anything else, if we wanted to.

At the other extreme: no, since Liskov substitution is an impossibly-high bar to reach; especially in a language that's as dynamic/loose as Python. For example, consider an expression like '"pop" in dir(mySet)'


Replies

tremonlast Thursday at 2:11 PM

> consider an expression like '"pop" in dir(mySet)'

  class frozenset:
    pass
  
  class set(frozenset):
    def pop(self, key):
      pass
I don't see why hasattr(mySet, 'pop') should be a problem here?
show 1 reply