title: unicode_literals and type()
body: <p>I'm having problems supporting python2 and python3 on a <code>type()</code> call. This demonstrates the problem:</p>
  
  <pre><code>from __future__ import unicode_literals
  
  name='FooClass'
  type(name, (dict,), {})
  </code></pre>
  
  <p>No problem on python3, but on python2:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 6, in &lt;module&gt;
      type(name, (dict,), {})
  TypeError: type() argument 1 must be string, not unicode
  </code></pre>
  
  <p>This is related to <a href="https://stackoverflow.com/questions/809796/any-gotchas-using-unicode-literals-in-python-2-6">Any gotchas using unicode_literals in Python 2.6?</a>. In that question, someone recommends typecasting to a bytestring, so naively I thought about using <a href="http://pythonhosted.org/six/#six.b" rel="nofollow noreferrer"><code>six.b()</code></a>:</p>
  
  <blockquote>
    <p>A “fake” bytes literal. data should always be a normal string literal.
    In Python 2, b() returns a 8-bit string. In Python 3, data is encoded
    with the latin-1 encoding to bytes.</p>
  </blockquote>
  
  <p>So it looks like this:</p>
  
  <pre><code>from __future__ import unicode_literals
  import six
  
  name='FooClass'
  type(six.b(name), (dict,), {})
  </code></pre>
  
  <p>But it fails on both python2 and python3:</p>
  
  <pre><code>$ python2 test.py 
  Traceback (most recent call last):
    File "test.py", line 6, in &lt;module&gt;
      type(six.b(name), (dict,), {})
  TypeError: type() argument 1 must be string, not unicode
  
  $ python3 test.py 
  Traceback (most recent call last):
    File "test.py", line 6, in &lt;module&gt;
      type(six.b(name), (dict,), {})
  TypeError: type() argument 1 must be str, not bytes
  </code></pre>
  
  <p>So it seems that <strong>really</strong>, <code>type()</code> wants a python2 str which is a python3 bytestring on python2, but it wants a python3 str which is a python2 unicode string on python3.</p>
  
  <p>What do you think ?</p>
  
  <p>Is there something I don't understand ?</p>
  
  <p>Or is there a real incompatibility with <code>type()</code> on python 2 and 3 ?</p>
  
  <p>Isn't there <em>any</em> way to have the same <code>type()</code> call supporting both 2 and 3 ?</p>
  
  <p>Shouldn't a tool like <code>six</code> provide a wrapper around <code>type()</code> in that case ?</p>