title: Inspect python class attributes
body: <p>I need a way to inspect a class so I can safely identify which attributes are user-defined class attributes. The problem is that functions like dir(), inspect.getmembers() and friends return all class attributes including the pre-defined ones like: <code>__class__</code>, <code>__doc__</code>, <code>__dict__</code>, <code>__hash__</code>. This is of course understandable, and one could argue that I could just make a list of named members to ignore, but unfortunately these pre-defined attributes are bound to change with different versions of Python therefore making my project volnerable to changed in the python project - and I don't like that.</p>
  <p>example:</p>
  <pre><code>&gt;&gt;&gt; class A:
  ...   a=10
  ...   b=20
  ...   def __init__(self):
  ...     self.c=30
  &gt;&gt;&gt; dir(A)
  ['__doc__', '__init__', '__module__', 'a', 'b']
  &gt;&gt;&gt; get_user_attributes(A)
  ['a','b']
  </code></pre>
  <p>In the example above I want a safe way to retrieve only the user-defined class attributes ['a','b'] not 'c' as it is an instance attribute. So my question is... Can anyone help me with the above fictive function <code>get_user_attributes(cls)</code>?</p>
  <p>I have spent some time trying to solve the problem by parsing the class in AST level which would be very easy. But I can't find a way to convert already parsed objects to an AST node tree. I guess all AST info is discarded once a class has been compiled into bytecode.</p>