r/Python • • May 30 '19

Dear python2 user

Post image
1.9k Upvotes

275 comments sorted by

View all comments

Show parent comments

8

u/jjdmol May 30 '19 edited May 30 '19

It isn't bad, but the required effort does scale with the size of your code base. 2to3 only covers some basics, many behavioural differences are more subtle. And python being interpreted you'll discover errors at run time, so will need good test coverage or do a lot of testing.

2

u/PeridexisErrant May 30 '19

Try the pyupgrade and future libraries - they do a lot more than 2to3 :-)

7

u/james_pic May 30 '19

Futurize did more harm than good when we tried it. It tries to paper over the genuinely different string semantics, and left us with something broken that we understood even less than what we started with.

Modernize is more conservative, and in our experience, gives a better starting point. If you've got a big codebase, you've still got an uphill battle ahead of you.

Also, use mypy type hints. In general, I hate them, but they're really helpful for clarifying type usage in legacy codebases.

1

u/PeridexisErrant May 30 '19

Hmm, thanks for the tip! I've use futurize --stage1 a fair bit but never really liked the second stage... though just getting syntax-compatible with Python 3 allows many more tools to work.

I'll try modernize :-)