title: How to conveniently define a list of named integer constants?
body: <p>I want to define constants, e.g. <code>A = 10; B = 20</code>, with these properties:</p>
  
  <ol>
  <li>'Normal' access: e.g. <code>A.value + B.value == 30</code> (or even <code>A + B == 30</code>)</li>
  <li>Allow duplicate values: e.g. <code>A = 10; B = 10</code></li>
  <li>Associated string for each variable: e.g. <code>A.name == "A"</code></li>
  <li>Listing: e.g. <code>[v.name for v in CONSTANTS]</code></li>
  <li>IDE support: auto-complete names, re-factorizations, etc.</li>
  <li>Adding a new constant requires <strong>one change</strong></li>
  <li>Importable: e.g. <code>from config import CONSTANTS</code></li>
  </ol>
  
  <p>In the end, the property #6 is the problem. Something like</p>
  
  <pre><code>A = 10
  B = 20
  
  A_NAME = "A"
  B_NAME = "B"
  
  CONSTANTS = { A_NAME: A, B_NAME: B }
  </code></pre>
  
  <p>would basically be the solution. But I would like to avoid this verbose code (if possible).</p>
  
  <hr>
  
  <p>This attempt comes very close:</p>
  
  <pre><code>import enum
  
  class CONSTANTS(enum.IntEnum):
      A = 10
      B = 20
  
  assert CONSTANTS.A + CONSTANTS.B == 30
  assert CONSTANTS.A.name == "A"
  assert CONSTANTS.__members__.keys() == ["A", "B"]
  assert CONSTANTS.__members__.values() == [10, 20]
  </code></pre>
  
  <p>but fails when two constants have the same value (property #2). One could also define a sub-class of <code>Enum</code> with a constructor taking <code>value</code>. But again, <code>A = 10; B = 10</code> would be mapped to the same instance, even though the name differs. One could now also add a name (or any other unused, but distinctive parameter to the constructor) to make this problem go away. But I would consider this approach unclean. For instance, <code>A = ("A", 10); B = ("B", 10); def __init__(self, _, value): ...</code>.</p>