Live data from Hacker News

How to Port from Python 2 to Python 3 (2019)

stxnext.com

31–40 of 51 posts

Re: How to Port from Python 2 to Python 3 (2019)

#31
Porting is a non-event for most non-large projects. In short:

- First cut a new major version

- Write a few tests if needed, they go a long way here.

- Update to 2.7 best practices and logging

- Run tests, commit

- Add a few future statements, commit

- Run pyflakes3 on it, fix, commit

- Run under 3.x/fix until clean, commit

However, if your project is huge and/or does a lot of string and bit twiddling it's excruciating. Hence the controversy between factions.

Re: How to Port from Python 2 to Python 3 (2019)

#32

Earlier quoted context omitted.

The main mental stumbling block I have about IPv6 (and I know it's kind of a silly one, but it's honestly what I feel on introspection) is that I can't remember an IPv6 address off by heart. IPv4 addresses just _feel_ so much more human-consumable than IPv6 addresses. I can't imagine myself using IPv6 addresses on the command line like I do with IPv4 now. There's also the issue that honestly, I have no idea what is u…

> is that I can't remember an IPv6 address off by heart. IPv4 addresses just _feel_ so much more human-consumable than IPv6 addresses. Stop remembering numbers meant for a machine, and use DNS. It will make your life so much easier. I spend ~$15/yr for my personal DNS name & hosting, and I never want to memorize an IPv4 or v6 address ever again. > I have no idea what is using IPv6 and what's using IPv4 right now. Any…

You're correct that the ISPs are dragging their feet, despite it allegedly being for their benefit - but exactly the same breakage risks apply. The cost/benefit tradeoff doesn't look good to them.

I just bought a new router. https://www.asus.com/uk/Networking/DSLAC68U/ It doesn't support IP6.

Re: How to Port from Python 2 to Python 3 (2019)

#33
post #22
post #5

Python 3 and IPv6 are the poster-children of how _not_ to do a major upgrade. I'm not sure what the right way is, but if the short-term advantages of the upgrade do not outweigh the immediate pain, prepare for the matter to drag out for _decades_.

IPv6 is a perfect example of the second-system effect [1] as in it added a bunch of things no one needed (but might need someday) and didn't solve roaming. All IPv4 really needed was a bigger address space. But as soon as you cross the mental threshold of making a breaking change (which expanding the IPv4 address space obviously was) then it's easier to convince yourself to make a bunch more breaking changes. And thi…

It's important to realize however that not everyone feels that way about Python3. I'm glad they fixed it and I wish they'd fixed more.

Re: How to Port from Python 2 to Python 3 (2019)

#34
post #23

Earlier quoted context omitted.

Upgrades are just hard. See perl5 to perl6 GWbasic to Qbasic to VB to VB.net you either make a clean break or keep all the warts, Either way folks are going to be unhappy. Keep the warts, COBOL, Fortran, C, C++, PHP, Excel

Ruby did a great job back in the day with their 1.8 release which changed the language to be Unicode friendly.

What did they do differently? I guess they benefited from hindsight.

Re: How to Port from Python 2 to Python 3 (2019)

#35
post #17

I've been doing a lot of Python 2 -> 3 lately, and found this to be one of the best actionable guides: https://portingguide.readthedocs.io/en/latest Also, using tox on the project to run tests against both python 2.7 and multiple versions of 3 and the work goes pretty quickly.

Looks like a lot of the guide assumes you want to run on Py2 and 3 concurrently. The time for that has passed to be honest. A clean port is easier to do.

Re: How to Port from Python 2 to Python 3 (2019)

#36
post #5

Python 3 and IPv6 are the poster-children of how _not_ to do a major upgrade. I'm not sure what the right way is, but if the short-term advantages of the upgrade do not outweigh the immediate pain, prepare for the matter to drag out for _decades_.

cf Itanium vs amd64

Re: How to Port from Python 2 to Python 3 (2019)

#37
post #7
post #5

Python 3 and IPv6 are the poster-children of how _not_ to do a major upgrade. I'm not sure what the right way is, but if the short-term advantages of the upgrade do not outweigh the immediate pain, prepare for the matter to drag out for _decades_.

At least Python3 brings an improvement. I still can't think of a good reason I should spend any time trying to figure out IPv6. Maybe my external router has to think about it, but that is about it. Edit: If you down vote me please say why I should care about IPv6

It sounds like you don't need to, and honestly, after all of these years I still don't know much about it either, because I haven't needed to.

One could argue that this is actually a significant benefit of IPv6, in practice.

Re: How to Port from Python 2 to Python 3 (2019)

#38
post #27

Earlier quoted context omitted.

> I'm not sure what the right way is The right way is to make sure that stuff that used to work in the previous version still works in the current version. Breaking people's work, especially work that spans multiple years, projects, knowledge, etc and expecting them to be happy about it is naive. Being condescending when they turn out to not be happy and try to avoid the unnecessary busywork forced on them does not h…

The most painful breaking change was the string treatment. Breakage was necessary if you wanted to make it possible to have more confidence in the basic building blocks of python. If you make a mistake when making a tool, you can either leave it forever, permanently causing pain for users forever, or you can try to find a path to fix it. That being said, a Python 3.0 which was _just_ “can’t call encode in string, dec…

The language we use at work (Delphi) changed its string type from ANSI to Unicode, and it took us less than a day to fix our ~500kloc code base, which does a _lot_ of string manipulations all over.

This was due to the hard work the people behind Delphi had put down to make the transition as smooth as possible.

Re: How to Port from Python 2 to Python 3 (2019)

#39

Earlier quoted context omitted.

> is that I can't remember an IPv6 address off by heart. IPv4 addresses just _feel_ so much more human-consumable than IPv6 addresses. Stop remembering numbers meant for a machine, and use DNS. It will make your life so much easier. I spend ~$15/yr for my personal DNS name & hosting, and I never want to memorize an IPv4 or v6 address ever again. > I have no idea what is using IPv6 and what's using IPv4 right now. Any…

> Stop remembering numbers meant for a machine, and use DNS This is not a good solution. A lot of times people use IPs because DNS is not available or is more complex to set up. Say you are: - Setting up and configuring a network. - Setting up the firewall. - Inspecting traffic and seeing where it goes. - Verifying that the DNS resolutions are being done correctly. Most people already use DNS, because it's more comfo…

> Text representation of IPv4 is easy to detect. IPv6 representation? Good luck with that.

This regex will detect any IPv6 address:

    ([0-9A-Fa-f]*:){2}[0-9A-Fa-f:.]*
Then you can feed matches to a real address parser to filter out false positives.

Re: How to Port from Python 2 to Python 3 (2019)

#40

Earlier quoted context omitted.

> is that I can't remember an IPv6 address off by heart. IPv4 addresses just _feel_ so much more human-consumable than IPv6 addresses. Stop remembering numbers meant for a machine, and use DNS. It will make your life so much easier. I spend ~$15/yr for my personal DNS name & hosting, and I never want to memorize an IPv4 or v6 address ever again. > I have no idea what is using IPv6 and what's using IPv4 right now. Any…

> Stop remembering numbers meant for a machine, and use DNS This is not a good solution. A lot of times people use IPs because DNS is not available or is more complex to set up. Say you are: - Setting up and configuring a network. - Setting up the firewall. - Inspecting traffic and seeing where it goes. - Verifying that the DNS resolutions are being done correctly. Most people already use DNS, because it's more comfo…

> A lot of times people use IPs because DNS is not available or is more complex to set up.

For the rare cases where a memorized IPv4 address was reasonable you should just assign simple IPv6 addresses ending in a short suffix like ::1. The prefix can be 64 bits or less, which isn't too much to remember, and will be the same for the entire network.

> For example, I can remember some network prefixes and know whether they are in building A or building B. IPv6 makes that much, much more difficult.

Nothing prevents you from assigning visually distinctive prefixes to different buildings. The larger address space actually makes this much easier. For example, you could use xxxx:yyyy:zzzz:a::/64 for every host in building A.

Post reply on HN