title: Create static instances of a class inside said class in Python
body: <p>Apologies if I've got the terminology wrong here—I can't think what this particular idiom would be called.</p>
  
  <p>I've been trying to create a Python 3 class that statically declares instances of itself inside itself—sort of like an enum would work. Here's a simplified version of the code I wrote:</p>
  
  <pre><code>class Test:
      A = Test("A")
      B = Test("B")
  
      def __init__(self, value):
          self.value = value
  
      def __str__(self):
         return "Test: " + self.value
  
  print(str(Test.A))
  print(str(Test.B))
  </code></pre>
  
  <p>Writing this, I got an exception on line 2 (<code>A = Test("A")</code>). I assume line 3 would also error if it had made it that far. Using <code>__class__</code> instead of <code>Test</code> gives the same error.</p>
  
  <pre><code>  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "&lt;stdin&gt;", line 2, in Test
  NameError: name 'Test' is not defined
  </code></pre>
  
  <p>Is there any way to refer to the current class in a static context in Python? I could declare these particular variables outside the class or in a separate class, but for clarity's sake, I'd rather not if I can help it.</p>
  
  <p>To better demonstrate what I'm trying to do, here's the same example in Java:</p>
  
  <pre><code>public class Test {
      private static final Test A = new Test("A");
      private static final Test B = new Test("B");
  
      private final String value;
  
      public Test(String value) {
          this.value = value;
      }
  
      public String toString() {
          return "Test: " + value;
      }
  
      public static void main(String[] args) {
          System.out.println(A);
          System.out.println(B);
      }
  }
  </code></pre>
  
  <p>This works as you would expect: it prints:</p>
  
  <pre><code>Test: A
  Test: B
  </code></pre>
  
  <p>How can I do the same thing in Python?</p>