[Web-SIG] WSGI for Python 3

Paul Davis paul.joseph.davis at gmail.com
Fri Aug 27 23:39:34 CEST 2010


On Fri, Aug 27, 2010 at 4:04 PM, Robert Brewer <fumanchu at aminus.org> wrote:
> Paul Davis wrote:
>> > Since the major stumbling block, irrespective of other changes,
>> > to any sort of agreement is still bytes vs unicode
>>
>> I ran into this while I was attempting to put together enough code to
>> play with a wsgiref2 that ran on both 2.x and 3.x. As Graham has
>> deftly pointed out, its a pretty big pain in the rear.
>>
>> Specifically, if we specify that all keys in the environ dictionary
>> are byte strings, then there's a noticeable amount of pain in trying
>> to write code that runs on both platforms. I object to 2to3.py on
>> religious grounds, so when I was implementing this I was doing so with
>> code that would run unmodified on both 2 and 3.
>
> Religion is what gets us into this mess. Pragmatism will get us out. We
> have two options:
>
>  1. Continue to try to write code that runs unmodified on Python 2 and
> 3, or that runs when 2to3 is applied. There is a morass of corner cases
> and state machines that behave differently depending on when you look at
> them lurking here. You can all see where that is getting us: nowhere. By
> the time you all discover how to write a spec that deals with all the
> pain points which 2to3 introduces, Python 2 will be dead and you will
> have wasted your time.
>  2. Write a Python 3 version of your code. Yes, it's more drudge work.
> Suck it up. To ameliorate that, make the Python 3 version the default as
> soon as possible. Deprecate the Python 2 branch. Backport features as
> necessary to the Python 2 branch (just as Python itself has been doing,
> if you notice). If you do that, we can write a WSGI for Python 3 now
> that doesn't suffer from any of the complexities of 2to3.
>
>
> Robert Brewer
> fumanchu at aminus.org
>

No. What got us into this mess was the idea that it would be a good to
silently type cast unicode objects into bytes. Perhaps I could've been
more clear on avoiding 2to3 though. I wanted to avoid coding any of
its oddities into a reference implementation because as you point out
it's just a source of confusion.

I'd like to point out that the code I posted works on both 2.x and
3.x. Its fairly easy to implement the backwards compatible code in
Python. There's nothing near the level of requiring a
branched/back-port strategy. Not to mention, a branched reference
implementation is bit of a contradiction in terms. The hard part is
figuring out a specification that doesn't suck when people try and
implement it on multiple interpreters.

Also, I think you're overestimating the rate at which people are going
to be converting to Python 3. I still have people ask for Python 2.4
support. I wouldn't be the least bit surprised if there's a WSGI 3
before we deprecate 2.x support.

HTH,
Paul Davis


More information about the Web-SIG mailing list