title: (kind of) Singleton Pattern in Python using Hash and `==`
body: <p>I am looking into ways to use a quasi Singleton Pattern in python. Quick problem description:</p>
  
  <p>I have objects that describe subset of a certain group. For simplicity assume integer numbers like in <code>set([1,2,3])</code>. In my case, comparison is difficult and if possible expensive, so I assume that if I have</p>
  
  <pre><code>complex_set1 = ...
  complex_set2 = ...
  </code></pre>
  
  <p>these are different. Also, all set are immutable (like frozenset). Except there exists the full and empty sets for convenience</p>
  
  <pre><code>full_set = FullSet()
  empty_set = EmptySet()
  </code></pre>
  
  <p>These seem to make sense to be singletons. One way would be to create one instance and just add it to the package <em>on import</em>. So that there exists only one and you cannot create another.</p>
  
  <p>Now my idea:</p>
  
  <p>Since I do not care if I have multiple objects as long as they are considered the same in any case (besides <code>a is b</code> is obviously false) I just make them look equal (like a singleton would). An example would be </p>
  
  <pre><code>len(set([FullSet(), FullSet()]))
  &gt;&gt;&gt; 1
  </code></pre>
  
  <p>So, I experimented with</p>
  
  <pre><code>def hash(self):
      return 0  # make sure all have the same hash
  
  def __eq__(self, other):
      if is instance(other, FullSet):
          return True
  
      return NotImplemented
  </code></pre>
  
  <p>Does this have a name? Is it considered a singleton pattern or something else?
  Should I use this or are there caveats to be aware of? </p>
  
  <p>Any comments on the hash value which is also used for other purposes than comparison? Does it make more sense to use e.g. <code>return hash(FullSet)</code></p>