title: Method overloading for different argument type in python
body: <p>I'm writing a preprocessor in python, part of which works with an AST.</p>
  
  <p>There is a <code>render()</code> method that takes care of converting various statements to source code.</p>
  
  <p>Now, I have it like this (shortened):</p>
  
  <pre><code>def render(self, s):
      """ Render a statement by type. """
  
      # code block (used in structures)
      if isinstance(s, S_Block):
          # delegate to private method that does the work
          return self._render_block(s)
  
      # empty statement
      if isinstance(s, S_Empty):
          return self._render_empty(s)
  
      # a function declaration
      if isinstance(s, S_Function):
          return self._render_function(s)
  
      # ...
  </code></pre>
  
  <p>As you can see, it's tedious, prone to errors and the code is quite long (I have many more kinds of statements).</p>
  
  <p>The ideal solution would be (in Java syntax):</p>
  
  <pre><code>String render(S_Block s)
  {
      // render block
  }
  
  String render(S_Empty s)
  {
      // render empty statement
  }
  
  String render(S_Function s)
  {
      // render function statement
  }
  
  // ...
  </code></pre>
  
  <p>Of course, python can't do this, because it has dynamic typing. When I searched for how to mimick method overloading, all answers just said "You don't want to do that in python". I guess that is true in some cases, but here <code>kwargs</code> is really not useful at all.</p>
  
  <p>How would I do this in python, without the hideous kilometre-long sequence if type checking ifs, as shown above? Also, preferably a "pythonic" way to do so?</p>
  
  <p><strong>Note:</strong> There can be multiple "Renderer" implementations, which render the statements in different manners. I can't therefore move the rendering code to the statements and just call <code>s.render()</code>. It must be done in the renderer class.</p>
  
  <p>(I've found some <a href="http://curtis.schlak.com/2013/06/20/follow-up-to-python-visitor-pattern.html" rel="noreferrer">interesting "visitor" code</a>, but I'm not sure if it's really the thing I want).</p>