[Python-ideas] Smoothing transition to Python 3
Nick Coghlan
ncoghlan at gmail.com
Sat Jun 4 04:05:37 EDT 2016
On 3 Jun 2016 13:17, "Neil Schemenauer" <nas-pythonideas at arctrix.com> wrote:
>
> I'm nearly finished porting a decently size application from Python
> 2 to Python 3. It has been a lot of work. I am dubious as to
> whether the port was really the best use of time. I can imagine
> there is still millions, possibly billions of lines of Python 2 code
> that has not yet been converted. Further, my guess is the lines of
> Python 2 code are still growing faster than the lines of Python 3
> compatible code. IMHO, we need to do better in making it easier for
> people to port code.
>
> Here is a thought that occured to me. Create a patched version of
> Python 3.x, making a stepping stone version for people porting from
> Python 2. I know this would have been useful for me. Specific
> changes that would be helpful, all generating warnings so code can
> be eventually fixed:
>
> - comparision with None, smaller than all other types
Static type checkers should already be able to find these cases today,
allowing them to be fixed incrementally pre-migration.
> - comparision of distinct types: use Python 2 behavior (i.e. order
> by type name)
As above (and we definitely won't revert it - it's one of the more
appreciated changes reported by educators)
> - mixing of unicode strings with byte strings: decode/encode
> using latin-1
Converting with latin-1 would be even less correct than Python 2's
behaviour of converting with ASCII (since it would allow arbitrary binary
data to be implicitly interpreted as text)
Type checkers don't generally help here yet, but are expected to in the
future.
> - dict objects: make keys() items() values() return special sequence
> that warns if iterated over multiple times or indexed as sequence
These can be mechanically converted by futurize in a way that avoids a
redundant copy on Python 2 (modernize will insert a redundant call to list
for the Python 2 case)
Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160604/30f15076/attachment.html>
More information about the Python-ideas
mailing list