title: elegant way to test python ASTs for equality (not reference or object identity)
body: <p>Not sure of the terminology here, but this would be difference between <code>eq?</code> and <code>equal?</code> in scheme, or the difference between <code>==</code>  and <code>strncmp</code> with C strings; where in each case the first would return false for two different strings that actually have the same content and the second would return true.</p>
  
  <p>I'm looking for the latter operation, for Python's ASTs.</p>
  
  <p>Right now, I'm doing this:</p>
  
  <pre><code>import ast
  def AST_eq(a, b):
      return ast.dump(a) == ast.dump(b)
  </code></pre>
  
  <p>which apparently works but feels like a disaster waiting to happen. Anyone know of a better way?</p>
  
  <p><strong>Edit</strong>: unfortunately, when I go to compare the two ASTs' <code>__dict__</code>'s, that comparison defaults to using the individual elements' <code>__eq__</code> methods. ASTs are implemented as trees of other ASTs, and their <code>__eq__</code> apparently checks for reference identity. So neither straight <code>==</code> nor the solution in Thomas's link work. (Besides which, I also don't want to subclass every AST node type to insert this custom <code>__eq__</code>.)</p>