#18363: Add a compatibility layer for Python 3
-----------------------------+------------------------------------
     Reporter:  claudep      |                    Owner:  nobody
         Type:  New feature  |                   Status:  reopened
    Component:  Python 3     |                  Version:  master
     Severity:  Normal       |               Resolution:
     Keywords:               |             Triage Stage:  Accepted
    Has patch:  1            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+------------------------------------

Comment (by vsajip):

 Replying to [comment:3 claudep]:
 > After some discussion, we will try to replace django.utils.py3 by the
 six module as django.utils.six.
 >
 > http://pypi.python.org/pypi/six

 Did this discussion happen on the {{{django-core}}} mailing list? I didn't
 see anything about it on {{{django-developers}}}.

 I've no ''very strong'' views on using {{{six}}}, it's a nice library and
 I used a few of the ideas, but IMO there are points which go against using
 it directly; for example, because of how Django uses metaclasses, and how
 {{{with_metaclass}}} works, we need to distinguish Django's usage from
 usage in third-party modules. Just grep my sources for {{{"DjangoBase"}}}
 to see what I mean. I actually use a pretty small subsection of {{{six}}}
 functionality, and did consider using it in {{{django.utils.six}}} style,
 but decided against it.

 You could of course keep {{{django.utils.py3}}} and in it just do {{{from
 .six import *}}} followed by any additions or redefinitions which are
 needed, like {{{n()}}}.

 I also think that using {{{io.StringIO}}} on 2.x, as I believe {{{six}}}
 does, will lead to problems; 2.x {{{io.StringIO}}} expects only Unicode to
 be written to it, and that's not what e.g. parts of the stdlib (like
 {{{json}}}) do when writing to streams. Example (using Python 2.6):

 {{{
 >>> from io import StringIO
 >>> fp = StringIO()
 >>> import json; json.dump({}, fp)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "C:\python26\lib\json\__init__.py", line 181, in dump
     fp.write(chunk)
   File "C:\python26\lib\io.py", line 1515, in write
     s.__class__.__name__)
 TypeError: can't write str to text stream
 >>>
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18363#comment:4>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to