r/programming • • Jun 27 '18

Python 3.7.0 released

https://www.python.org/downloads/release/python-370/
2.0k Upvotes

383 comments sorted by

View all comments

Show parent comments

66

u/[deleted] Jun 28 '18

Yes really. Mine too. Companies have a lot of old code and there's not much incentive to upgrade it to Python 3 for basically zero benefit.

Actually, it's a big risk because these scripts are generally "tested" by using them and reporting bugs. Upgrade to Python 3 and due to its dynamic typing you're probably going to introduce a load of bugs.

Also I have noticed even some big new projects, e.g. Tensorflow, target Python 2 first and then add Python 3 support later.

The idea that the 2/3 mess is over is unfortunately not true.

31

u/vivainio Jun 28 '18

The "zero benefit" is not true anymore

1

u/anacrolix Jun 28 '18

Example?

2

u/vivainio Jun 28 '18

Types and asyncio come to mind first

4

u/13steinj Jun 28 '18

Types aren't beneficial to every developer. Asyncio has severe usability issues, I'd rather use gevent in an async manner.

4

u/vivainio Jun 28 '18

Ok, f-strings then?

2

u/13steinj Jun 28 '18

While I like them, their only benefit is reducing a call of "string with idens".format(explicits_for_idens) to f"string with explicits for idens", it's syntactic sugar that saves you ".", "ormat", and the parenthesis, nothing more. And it introduces backwards incompatible in minor version numbers, which it really shouldnt.

4

u/somebodddy Jun 29 '18

it's syntactic sugar that saves you ".", "ormat", and the parenthesis, nothing more

I disagree. The greatest benefit of f-strings is that the save you the need to zip the values in your head. Consider this:

'a={} x={} u={} z={} y={}'.format(a, x, u, y, z)

You need to make sure that the list of {}s matches the format arguments. Compare to this:

f'a={a} x={x} u={u} z={y} y={z}'

Now that each expression is written in the place it is supposed to be formatted, we can clearly see that I've "accidentally" mixed y and z. The same mistake exists in the .format() version, but much harder to notice.

In order to avoid that, we can do this:

 'a={a} x={x} u={u} z={z} y={y}'.format(a=a, x=x, u=u=, z=z, y=y)

But now we have to write each variable 3 times.

Of course, this can be solved with .format(**locals()) (or .format_map(locals())). Expect...

a = 1

def foo():
    b = 2
    print('{a}, {b}'.format(**locals()))

foo()

{a} is not a local variable... Luckily, we can use .format(**locals(), **globals())! But then:

a = 1
b = 2

def foo():
    b = 2
    print('{a}, {b}'.format(**locals(), **globals()))

foo()

Now b appears in the argument list multiple times...

And it introduces backwards incompatible in minor version numbers, which it really shouldnt.

What backwards incompatibility? f'...' is a syntax error in older versions of Python, so it shouldn't break older code. Or am I missing something?

→ More replies (0)