title: Recognizing attributes type, when working with properties
body: <p><strong>Example situation:</strong></p>
  
  <p>So, lets assume I'm creating some inspection tool, and I wanna have a methods for listing callable fields, which are some methods, for listing data fields (normal attributes) and properties (so I can also add information on which descriptor methods are declared, to see if attribute is constant, etc).</p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>How do I iterate over some objects fields?</li>
  <li>How do I recognise whether some field is property? (Checking whether it is callable is easy, with <code>callable</code> builtin function, just trying to call some object, or checking whether it has <code>__call__</code> attribute; those ways of checking are listed from most to least reliable and safe)</li>
  </ol>
  
  <p><strong>Known approaches:</strong></p>
  
  <p><em>Ad. 1</em></p>
  
  <p>Easiest way I can think of is using <code>dir()</code> or checking <code>__slots__</code>. Still, I know that <code>dir()</code> is intended to be used in REPL mode only, but I dont know why, so here's some bonus question: <em>"Why shouldn't I use <code>dir()</code> in real-life usage? Or should I?"</em>.</p>
  
  <p>Also, I think I remember something about <code>__dict__</code>, but I'd have to consult <a href="http://docs.python.org/3.4/reference/datamodel.html" rel="nofollow noreferrer">Data model</a> to be sure how to use it, and if it would do what I need. Anyway, I'd also have to consult that article when trying to use <code>__slots__</code>.</p>
  
  <p><em>Ad. 2</em></p>
  
  <p>No freaking idea. I tried using plain <code>getattr(obj, name)</code>, <code>object.__getattribute__(obj, name)</code>, <code>obj.__getattribute__(name)</code>, <code>obj.__getattr__(name)</code> (for some cases only) to get descriptor object (one that implements <code>__get__</code>, <code>__set__</code>, etc) and check for those methods, but instead, <code>obj.name.__get__(...)</code> is called.</p>
  
  <p><strong>Post Scriptum</strong></p>
  
  <p>This isn't real-life example, more like my way of figuring out nuances of python. If there is some reason why I shouldn't even try to do it, I'll be glad to hear it, but I will also like to know how to do it, if I REALLY (like "I know that is bad, but if I won't do it, my boss will fire me"-really) need to.</p>
  
  <p>I'm mostly interested in p3.3+, but those question stand for p2.7.x too.</p>
  
  <p><strong>== EDIT ==</strong> </p>
  
  <p><em>Ad. 2</em></p>
  
  <p>With help from <a href="https://stackoverflow.com/users/2357112/user2357112">user2357112</a> I got this:</p>
  
  <pre><code>&gt;&gt;&gt; class A:
  ...     @property
  ...     def x(self):
  ...         return 1
  ... 
  &gt;&gt;&gt; a = A()
  &gt;&gt;&gt; a.x
  1
  &gt;&gt;&gt; isinstance(a.x, int)
  True
  &gt;&gt;&gt; isinstance(a.x, property)
  False
  &gt;&gt;&gt; isinstance(type(a).x, property)
  True
  </code></pre>