title: How to intercept class creation and add attribute using a metaclass?
body: <p>In the following code, I want metaclass <code>NameMeta</code> to add attribute <code>gender</code> to <code>MyName</code> class in case this class does not declare that attribute.</p>
  
  <pre><code>class NameMeta(type):
      def __new__(cls, name, bases, dic):
          if 'gender' not in dic:
              setattr(name, 'gender', 'Male')
          return super().__new__(cls, name, bases, dic)
  
  class MyName(metaclass=NameMeta):
      def __init__(self, fname, lname):
          self.fname = fname
          self.lname = lname       
      def fullname(self):
          self.full_name = self.fname + self.lname
          return self.full_name 
  inst = MyName('Joseph ', 'Vincent')
  print(MyName.gender)
  </code></pre>
  
  <p>This is the output that I am getting:</p>
  
  <pre class="lang-none prettyprint-override"><code>&lt;ipython-input-111-550ff3cfae41&gt; in __new__(cls, name, bases, dic)
        2     def __new__(cls, name, bases, dic):
        3         if 'gender' not in dic:
  ----&gt; 4             setattr(name, 'gender', 'Male')
        5         return super().__new__(cls, name, bases, dic)
        6 
  
  AttributeError: 'str' object has no attribute 'gender'
  </code></pre>
  
  <p>I know this error makes sense since <code>name</code> is a string.
  My question is, how can I access <code>MyName</code> class as an object in the metaclass so that I can add the attribute?</p>