[Python-Dev] Smoothing the transition from Python 2 to 3 (original) (raw)
Paul Moore p.f.moore at gmail.com
Fri Jun 10 04:35:45 EDT 2016
- Previous message (by thread): [Python-Dev] Smoothing the transition from Python 2 to 3
- Next message (by thread): [Python-Dev] Smoothing the transition from Python 2 to 3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 10 June 2016 at 03:13, Barry Warsaw <barry at python.org> wrote:
In my own experience, and IIRC Amber had a similar experience, the ease of porting to Python 3 really comes down to how bytes/unicode clean your code base is. Almost all the other pieces are either pretty manageable or fairly easily automated. But if you're code isn't bytes-clean you're in for a world of hurt because you first have to decide how to represent those things. Twisted's job is especially fun because it's all about wire protocols, which I think Amber described as (paraphrasing) bytes that happen to have contents that look like strings.
Although I have much less experience with porting than many others in this thread, that's my experience as well. Get a clear and well-understood separation of bytes and strings, and the rest of the porting exercise is (relatively!) straightforward. But if you just once think "I'm not quite sure, but I think I just need to decode here to be safe" and you'll be fighting Unicode errors for ever.
My hope is that static typing tools like MyPy could help here. I typically review Python 2 code by mentally categorising which functions (theoretically) take bytes, which take strings, and which are confused. And sort things out from there. Type annotations seem like they'd help that process. But I've yet to use typing in practice, so it may not be that simple.
Paul
- Previous message (by thread): [Python-Dev] Smoothing the transition from Python 2 to 3
- Next message (by thread): [Python-Dev] Smoothing the transition from Python 2 to 3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]