title: How to inject class-variable annotations in Python 3.7+?
body: <p>In Python 3.7, static fields can be annotated with the following syntax defined in <a href="https://www.python.org/dev/peps/pep-0526/#class-and-instance-variable-annotations" rel="nofollow noreferrer">PEP 526</a>:</p>
  
  <pre><code>class A:
     foo: int
  </code></pre>
  
  <p>How can I make these annotations later on, after the class is defined? I would expect the following to work:</p>
  
  <pre><code>A.bar : float
  </code></pre>
  
  <p>However, it doesn't seem to have an identical effect to the first code. When we look at <code>A</code>'s <code>__dict___</code>, those two snippets don't have the same effect.</p>
  
  <p>After example 1 <em>and</em> after example 2, we get identical <code>__dict__</code>'s, i.e. the second example must show effect somewhere else. The dict created is:</p>
  
  <pre><code>&gt;&gt; pprint(A.__dict__):
  mappingproxy({'__annotations__': {'foo': &lt;class 'int'&gt;}, # &lt;-!
                '__dict__': &lt;attribute '__dict__' of 'A' objects&gt;,
                '__doc__': None,
                '__module__': '__main__',
                '__weakref__': &lt;attribute '__weakref__' of 'A' objects&gt;})
  </code></pre>
  
  <p>I don't think editing <code>__annotations__</code> is a "good" method of achieving what I want, especially because I'm not sure if it's the only case where <code>foo</code> is registered.</p>
  
  <p>What is the proper way to do this?</p>