title: Python Enum prevent invalid attribute assignment
body: <p>When I use the Functional API to create an Enum, I get back an Enum object that allows arbitrary assignment (i.e. it has a <code>__dict__</code>):</p>
  <pre class="lang-py prettyprint-override"><code>e = enum.Enum('Things',[('foo',1),('bar',2)])
  e.baz = 3
  </code></pre>
  <p>The item does not appear in the list:</p>
  <pre class="lang-py prettyprint-override"><code>list(e)
  [&lt;foo.foo: 1&gt;, &lt;foo.bar: 2&gt;]
  </code></pre>
  <p>But it can still be referenced:</p>
  <pre class="lang-py prettyprint-override"><code>if thing == e.baz: ...
  </code></pre>
  <p>Now while it seems unlikely to ever occur, one of the reasons I want to use an Enum is to prevent spelling mistakes and string literals, and for those things to be caught when a module is imported or as early as possible.</p>
  <p>Is there a way to dynamically build an Enum that behaves more like a <code>__slots__</code> object that does not allow arbitrary attributes to be assigned?</p>