News for hackers. Stuff that matters.
Re:Sunsetting Python 2 by mantap on Monday September 09, 2019 @06:58AM (#20916990)
You couldn't switch to Python 3 until the middle part of this decade unless the stars aligned with your dependencies, the library support wasn't there. And the first releases of Python 3 were glorified betas, the first "usable" version of Python 3 is often considered to be version 3.3 released in 2012.
Re:Sunsetting Python 2 by ensignavenger on Monday September 09, 2019 @07:34AM (#20917160)
But you could easily write Python 3 compatible code so that upgrading once your dependacies were ready was easy. You also could have contributed to your dependancies to help them become Python 3 compatible.
Re:Sunsetting Python 2 by pfranz on Monday September 09, 2019 @01:58PM (#20920578)
I often hear this, but I just don't see this working in practice. A very similar example I have experience with, I've often worked with people who tried to write code that would be "compatible with Windows" (I primary work in a Linux environment). It makes the code more difficult to read and as soon as you try and run it in Windows it fails spectacularly.

You can write code that's compatible with both Python 2 and 3, but I don't think you can expect to be using Python 2 exclusively and write code that works well in Python 3 unless you're constantly running it with Python 3. Especially, if you don't have much firsthand Python 3 experience. This is much easier if your code is isolated from those dependencies and you write tests that run in both Python 2 and 3, but that's quite a bit more of a commitment than you seem to be implying.

Re:Sunsetting Python 2 by ensignavenger on Monday September 09, 2019 @06:32PM (#20923205)
There are a ton of open source projects that have done python 2/3 simultaneously in practice.

I get your point though about not being able to run full integration tests due to dependencies. Still, if you were making a good effort to keep the code Python 3 compliant, it would make upgrading much easier.

Also, my other suggestion- contributing to Python 3 compatibility for modules you depend on! That will give you Python 3 experience :)

Re:Sunsetting Python 2 by mikepurvis on Monday September 09, 2019 @09:45AM (#20918066)
Quick: run a shell command, split up the reply by line, run a regex on each line, and save the results to a yaml file— now, does what you wrote work correctly on both Python 2.7 and Python 3.3+? Yeah that's what I thought.

It's still hard to get bilingual Python correct today, and it was considerably harder before 3.3.

Re:Sunsetting Python 2 by radus on Monday September 09, 2019 @02:50PM (#20921068)
Okay, I did it.

    import subprocess
    import re
    import yaml

    output = subprocess.check_output(['ls', '-l'], universal_newlines=True)
    matching_lines = []

    for line in output.splitlines():
        if re.search(r'total', line):
            matching_lines.append(line)

    with open('matching_lines.yaml', 'w') as f:
        f.write(yaml.dump(matching_lines))
Python 3.7: https://repl.it/repls/PotableDamagedAutocad

Python 2.7: https://repl.it/repls/OrchidDirtyNotification

Re:Sunsetting Python 2 by mikepurvis on Monday September 09, 2019 @08:12PM (#20923924)
Nice. Yeah my life got a lot easier when I learned about `universal_newlines` changing the subprocess return type under Python 3.

The much worse case of this that I dealt with a few years ago was reading in and modifying XML files, and then saving the modified XML contents as strings in a yaml file (a keyed cache). The input XML files (which I didn't control) were not consistent about having the encoding marked, and that really made things a mess for ElementTree.

A taste: https://github.com/ros-infrastructure/rosdistro/search?q=utf...

Re:Sunsetting Python 2 by slavik81 on Tuesday September 10, 2019 @07:50AM (#20927180)
This program would crash with a UnicodeEncodeError upon encountering any file with a non-latin character in its name on Windows with Python 3.5 or earlier.

I know that's not the version of Python you were targeting, and I know you didn't write this program to be cross-platform, but I wrote a similar program and I was repeatedly surprised by those sorts of problems. I don't entirely agree with mikepurvis, but I do feel his pain.

Re:Sunsetting Python 2 by weberc2 on Monday September 09, 2019 @10:26AM (#20918477)
No one is arguing that upgrading would be trivial; the argument is that it's necessary work that could have been started 10 years ago. Also, if you run your unit tests on Python 2 and 3, you'll get pretty good pretty fast at writing 2-3 compatible code.
Re:Sunsetting Python 2 by mikepurvis on Monday September 09, 2019 @10:33AM (#20918549)
The comment I was specifically replying to asserted that "you could easily write Python 3 compatible code", and could have been doing so 10 years ago.

This is simply untrue— there are a dozen small stumbling blocks that mean that writing bilingual code has a real cost. And it's not as easy as just having the right CI setup, especially if it's ten years ago and most of your dependencies haven't migrated.

Re:Sunsetting Python 2 by weberc2 on Monday September 09, 2019 @10:50AM (#20918713)
Ah, I see the confusion. In this case, "easily" is relative. The assertion "you could easily write Python 3 compatible code" was in response to the (implied?) assertion "you can't do anything to migrate unless your dependencies are migrated". Perhaps "simply" would have been a better word choice than "easily". To your point, writing 2-3 compatible code has a real cost, but to the GP's point, it's the obvious solution to the "can't do anything until deps are migrated" problem.
Re:Sunsetting Python 2 by logifail on Monday September 09, 2019 @01:05PM (#20919977)
> To your point, writing 2-3 compatible code has a real cost, but to the GP's point, it's the obvious solution to the "can't do anything until deps are migrated" problem

Q: Ten years ago how would you have explained to your manager that you needed your team to start writing 2-3 compatible code, which obviously takes considerably more time and effort than sticking with 2 compatible code?

Re:Sunsetting Python 2 by joshuamorton on Monday September 09, 2019 @09:21PM (#20924285)
It doesn't take considerably more time.

At this point, all the code I write is 2/3 compatible, and the things that annoy me are all py3 only features. Backwards compatibility stuff is pretty easy. Most of the easy problems are easy, and six has solved all the hard ones for like 7 years.

And I've been writing some of my code 2/3 compatible since 3.4.

Re:Sunsetting Python 2 by mehrdadn on Monday September 09, 2019 @07:47AM (#20917230)
> But you could easily write Python 3 compatible code so that upgrading once your dependacies were ready was easy.

This sounds a bit like telling someone, oh, you could've easily started driving an EV, so that once charging stations were actually out there, you'd have been ready...

Re:Sunsetting Python 2 by ericvsmith on Monday September 09, 2019 @07:58AM (#20917308)
> This sounds a bit like telling someone, oh, you could've easily started driving an EV, so that once charging stations were actually out there, you'd have been ready...

While car analogies are notoriously bad, it's much more like "I'm going to buy a plug-in hybrid and use gasoline until charging stations are widely available". You can write code that works in Python 2 that takes zero effort to run in Python 3. I (and many others) have been doing this for years. Just look at the number of packages on PyPI that run, unmodified, on 2 and 3.

[Edit: gas -> gasoline]

Re:Sunsetting Python 2 by mehrdadn on Monday September 09, 2019 @08:03AM (#20917334)
I try to write compatible code myself too, and the only reason it's "zero effort" to run in Python 3 is that I've already invested said effort when making it compatible. Getting strings and paths and stdio to be cross-compatible and working correctly in both 2 and 3 can be quite painful in my experience. Which was kind of my point with the vehicle analogy. It requires a significant investment that you're ignoring, and lack of enough underlying support to justify it during that time.
Re:Sunsetting Python 2 by weberc2 on Monday September 09, 2019 @10:31AM (#20918517)
Driving an EV without charging stations is (nearly) useless. You can still run Python 2-3 code with a Python 2 interpreter with no significant consequence.
Re:Sunsetting Python 2 by WorldMaker on Monday September 09, 2019 @04:57PM (#20922400)
EV drivers don't need charging stations at all if they have an open plug at home or at work. The metaphor still sort of works that Python developers had plenty of time where maybe they didn't have enough charging stations on the wide open highway roads of Production to use Python 3 there, but certainly could have been happy to use an EV to commute from home (hobby projects) to the work parking lot (side projects, automation projects, new projects) and back while they waited for those "charging stations" to be built.
Re:Sunsetting Python 2 by weberc2 on Monday September 09, 2019 @07:00PM (#20923431)
I don't want to debate the amount of shoehorning necessary to validate the metaphor. We all understand concretely the issue at hand, the metaphor is only obfuscating at this point.
Re:Sunsetting Python 2 by collinmanderson on Monday September 09, 2019 @10:13AM (#20918347)
I feel like there were 3 steps:

- 2008-2012 Python 3 becoming usable (byte formatting, six library)

- 2012-2016 Libraries (Django, etc) becoming compatible

- 2016-today Applications (Trac, Ansible, Chrome[1], etc) becoming compatible.

[1] https://bugs.chromium.org/p/chromium/issues/detail?id=942720

Re:Sunsetting Python 2 by oblio on Monday September 09, 2019 @08:24AM (#20917439)
2012 was 7 years ago.