#25218: python_2_unicode_compatible causes infinite recursion when
super().__str__() is called
-------------------------------+--------------------------------------
     Reporter:  jscn           |                    Owner:  nobody
         Type:  Uncategorized  |                   Status:  new
    Component:  Utilities      |                  Version:  1.8
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by charettes):

 I reproduce with the correct `super()` call on Python 2.7:

 {{{#!python
 In [1]: from django.utils.six import python_2_unicode_compatible

 In [2]: @python_2_unicode_compatible
 class A(object):
     def __str__(self):
         return str('a')
    ...:

 In [3]: str(A())
 Out[3]: 'a'

 In [4]: unicode(A())
 Out[4]: u'a'

 In [5]: class B(A):
     def __str__(self):
         return str('b') + super(B, self).__str__()
    ...:

 In [6]: str(B())
 Out[6]: 'ba'

 In [7]: unicode(B())  # Notice how B.__str__() isn't called.
 Out[7]: u'a'

 In [8]: @python_2_unicode_compatible
 class C(A):
     def __str__(self):
         return str('c') + super(C, self).__str__()
    ...:

 In [9]: str(C())
 --------------------------------------------------------------------------
 ...
 <ipython-input-8-efd21456ef94> in __str__(self)
       2 class C(A):
       3     def __str__(self):
 ----> 4         return str('c') + super(C, self).__str__()
       5

 django/django/utils/six.pyc in <lambda>(self)
     810                              klass.__name__)
     811         klass.__unicode__ = klass.__str__
 --> 812         klass.__str__ = lambda self:
 self.__unicode__().encode('utf-8')
     813     return klass
     814

 RuntimeError: maximum recursion depth exceeded in __subclasscheck__
 In [10]: unicode(C())
 --------------------------------------------------------------------------
 ...
 <ipython-input-8-efd21456ef94> in __str__(self)
       2 class C(A):
       3     def __str__(self):
 ----> 4         return str('c') + super(C, self).__str__()
       5

 django/django/utils/six.pyc in <lambda>(self)
     810                              klass.__name__)
     811         klass.__unicode__ = klass.__str__
 --> 812         klass.__str__ = lambda self:
 self.__unicode__().encode('utf-8')
     813     return klass
     814

 RuntimeError: maximum recursion depth exceeded in __subclasscheck__
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25218#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.21b13a0d3f8246aa63140eadc89b7862%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to