Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

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

 * cc: tzanke@… (added)


--
Ticket URL: 
Django 
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.695a629acedd4c334a82382bdb9662b8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

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

 * status:  new => closed
 * resolution:   => wontfix


--
Ticket URL: 
Django 
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.dfaeec70b485108489eed68dc64a2546%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-06 Thread Django
#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 aaugustin):

 `@python_2_unicode_compatible` changes the implementation of `__str__` and
 `__unicode__` on Python 2. If you want to call the `__str__` method you
 defined in the parent class, you have to call `super(B,
 self).__unicode__()`.

 The following works both on Python 2 and 3:

 {{{
 from __future__ import print_function, unicode_literals

 from django.utils.six import PY3, python_2_unicode_compatible

 @python_2_unicode_compatible
 class A(object):
 def __str__(self):
 return 'a'

 @python_2_unicode_compatible
 class B(A):
 def __str__(self):
 text_method = '__str__' if PY3 else '__unicode__'
 return getattr(super(B, self), text_method)() + 'b'

 print(str(B()))
 }}}

 This version is more readable:

 {{{
 from __future__ import print_function, unicode_literals

 from django.utils.six import PY3, python_2_unicode_compatible

 @python_2_unicode_compatible
 class A(object):
 def text(self):
 return 'a'
 __str__ = text

 @python_2_unicode_compatible
 class B(A):
 def text(self):
 return super(B, self).text() + 'b'
 __str__ = text

 print(str(B()))
 }}}

 This isn't obvious but I can't see a way around it. (I'm the original
 author of this decorator which was added to `six` later.)

--
Ticket URL: 
Django 
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.4a09ae5f5219e81f0c0459f5b1316538%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-05 Thread Django
#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 jscn):

 Replying to [comment:7 timgraham]:
 > I think the `future` library does some monkeypatching to allow it to
 work, but it would be interesting to know if this issue can be reproduced
 without it.

 Correct, I should have mentioned that in the ticket, sorry. As @charettes
 demos below, it's reproducible with the normal Python2-style `super` call.

--
Ticket URL: 
Django 
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.d3e1e0f308e498c824d7eae98e41%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-05 Thread Django
#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())
 --
 ...
  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 (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())
 --
 ...
  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 (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: 
Django 
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.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-05 Thread Django
#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 timgraham):

 I think the `future` library does some monkeypatching to allow it to work,
 but it would be interesting to know if this issue can be reproduced
 without it.

--
Ticket URL: 
Django 
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.ef596fdbdf207ab8147b4f2c9a19b377%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-05 Thread Django
#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 aaugustin):

 I don't understand how `super().__str__()` can work as `super()` without
 arguments is illegal in Python 2.

--
Ticket URL: 
Django 
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.b4aede2a16bb71f188ab6ebfc8340286%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-04 Thread Django
#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 jscn):

 I believe there's a related infinite-recursion problem on saving models in
 certain circumstances but I haven't had time to extract a useful example
 from the project in which I'm seeing it. At this point, I think it's a
 problem with the implementation of `__str__` in
 `django.db.models.base.Model`.

--
Ticket URL: 
Django 
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.6fab3a213fa8d17ec5d222d3be0b2caa%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-04 Thread Django
#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 jscn):

 Unfortunately not, if you include a unicode character in `Bar.extra` and
 remove the decorator, you'll get something like:

 {{{#!python
 Traceback (most recent call last):
   File "./recursion.py", line 34, in 
 print(b)
 UnicodeEncodeError: 'ascii' codec can't encode character u'\u1546' in
 position 4: ordinal not in range(128)
 }}}

--
Ticket URL: 
Django 
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.4b8392ed24521e5b3ec8b7ae0ec9761d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-04 Thread Django
#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 timgraham):

 Can you omit `@python_2_unicode_compatible` on the subclass?

--
Ticket URL: 
Django 
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.dbf2ab55181f322a1b0d8bca975117d5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-04 Thread Django
#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 jscn):

 Apologies, I should have specified that this problem only occurs with
 Python 2 (I have tried only with 2.7.6). My understanding is that
 `python_2_unicode_compatible` is a noop in Python 3.

 I also notice now that `python_2_unicode_compatible` is actually in the
 `six` library, so it might be more appropriate for me to make a ticket for
 that project than here.

--
Ticket URL: 
Django 
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.d4197e43a1e7f11cdf63e7e41c1b28da%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-04 Thread Django
#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
---+--
Changes (by timgraham):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 The attached script prints "foo bar" for me on Python 3.4. Is it supposed
 to reproduce the infinite recursion?

--
Ticket URL: 
Django 
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.36c85b9687b4fdc1504fc5bcb9ba1ab2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-03 Thread Django
#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  |  Easy pickings:  0
UI/UX:  0  |
---+
Changes (by jscn):

 * Attachment "recursion.py" added.


--
Ticket URL: 
Django 
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.68b3d80199cb8258d6e2ca3a13775231%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #25218: python_2_unicode_compatible causes infinite recursion when super().__str__() is called

2015-08-03 Thread Django
#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 |   Keywords:
 Triage Stage:  Unreviewed |  Has patch:  0
Easy pickings:  0  |  UI/UX:  0
---+
 I have a class `A` which implements `__str__()` and is decorated with
 `@python_2_unicode_compatible`.

 I have sub-class of `A`, `B`, and `B` 's implementation of `__str__()`
 calls `super().__str__()`.

 When I call `b.__str__()`, I get the following error: `RuntimeError:
 maximum recursion depth exceeded while calling a Python object`.

 Partial traceback:

 {{{#!python
   File "/home/josh/Desktop/temp/djtest/local/lib/python2.7/site-
 packages/django/utils/encoding.py", line 42, in 
 klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
   File "recursion.py", line 27, in __str__
 super().__str__(),
   File "/home/josh/Desktop/temp/djtest/local/lib/python2.7/site-
 packages/django/utils/encoding.py", line 42, in 
 klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
   File "recursion.py", line 27, in __str__
 super().__str__(),
 }}}

 The docs
 
(https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.encoding.python_2_unicode_compatible)
 imply that the decorator should be applied to *any* class implementing
 `__str__()`

--
Ticket URL: 
Django 
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/047.d7efe90db95acc681b8a1cfdcd9f3047%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.