r/Python • Freelancer. AnyFactor.xyz • Sep 16 '20

News An update on Python 4

Post image
3.3k Upvotes

389 comments sorted by

View all comments

-11

u/NTWK_Identifier Sep 16 '20

3.9 -> 3.10

This makes me irrationally angry.

9

u/studiov34 Sep 16 '20

You must hate ipv4 addresses.

8

u/Jethro_Tell Sep 16 '20

Why?

-3

u/Leav Sep 16 '20

Because 3.10 = "3.1 with more precision" to engineers and scientists and basically all non-developer users.

How would python sort these lists: [3.8,3.9,3.10] or ["3.8","3.9","3.10"]?

14

u/Karnyl Sep 16 '20

If you used a library aware of how versions should be sorted, like semver or distutils.version, then they would be sorted correctly.

>>> from distutils.version import LooseVersion
>>> versions = ["3.8","3.9","3.10"]
>>> sorted(versions, key=LooseVersion)
"3.8","3.9","3.10"

4

u/flying-sheep Sep 16 '20

Please don't use distutils.version anymore, it doesn't follow PEP 440, which defines how Python package versions work. Use packaging.version instead.

0

u/Leav Sep 17 '20

Sure, but to newbies this is confusing and non intuitive, that's all we're saying here.

No one is saying this is wrong or should change.

7

u/netgu Sep 16 '20

This isn't about engineering or science so that point doesn't matter, honestly.

I realize that engineers/scientists will use python. When they do that they are functioning as developers/software engineers (those are just facts)and as such they should get comfortable dealing with the software development side of the software development they are doing.

There are rules about how these numbers work that mean the world to developers and software engineers (this is the place this matters and so these are the concerns that dictate how it is done) to the point that there is an entire standard built around it that will answer all your questions (including the ordering one):

https://semver.org/

1

u/Leav Sep 17 '20

Acceptable. I wasn't trying to say that the way versions work should change for the benefits of newcomers, just that it was confusing.

2

u/flying-sheep Sep 16 '20

None of these lists contain versions. Try this one:

from packaging.version import Version

versions = [Version(v) for v in ["3.8", "3.9", "3.10"]]
assert sorted(versions) == versions

For versions containing only numbers (and not e.g. 3.9b1) you can also think of them as tuples of integers.

0

u/Leav Sep 17 '20

Yes, I understand this is how versions work, but to someone who is not familiar with them, it looks extremely weird and confusing.

1

u/flying-sheep Sep 17 '20

Well, welcome to human language notation. There's things that look similar but aren't the same. Boohoo.

2

u/pepoluan Sep 17 '20

The problem is people treating "." as decimal point instead of "arbitrary separator that happens to be a period".

Limiting oneself to "3.9" is ambiguous. But how do you consider "3.9.1"? Or to use latest Python stable, "3.8.5"?

When facing version numbers, one must split on this "arbitrary separator that happens to be a period" first, integer-ize the portions, tuple-ify the result ... then perform a comparison.

Now to answer your question, "how to sort":

list_of_version_strings = ["3.10", "3.8", "3.9", "3.8.5"]
converter = lambda x: tuple(map(int, x.split(".")))
list_of_version_tuples = list(map(converter, list_of_version_strings))
sorted(list_of_version_tuples)

# Result is:
# [(3, 8), (3, 8, 5), (3, 9), (3, 10)]

3

u/netgu Sep 16 '20

Try this version number on for size:

Eclipse IDE 2020-09-4.17.0

That style is visually jarring for me.

2

u/flying-sheep Sep 16 '20

I like it, it makes clear that this part of the version is a date, by using the one and only date formatting: ISO 8601, a standard so useful that I know its number by heart.

2

u/pepoluan Sep 17 '20

I also know ISO8601 by heart.

And that monstrosity is not ISO8601.

I'm talking of the "2020-09-4" part: the single-digit last part is not ISO8601-compliant, not even by a long shot.

3

u/flying-sheep Sep 17 '20

Oh. I missed that detail. WTF?!

1

u/Pulsar1977 Sep 17 '20

I also know ISO8601 by heart.

Clearly you don't. The date is "2020-09", which is perfectly valid. "4.17.0" is the version number. "4" is not a day.

1

u/pepoluan Sep 18 '20 edited Sep 18 '20

I do know ISO8601 by heart. What I do not know is the semantics of Eclipse versioning.

For me, the dash implies that 2020 and 09 and 4 are tied together. And the period separates the portions of the versioning system. So, in my point of view as someone who doesn't know Eclipse's versioning system, the version has three parts: "2020-09-4" and "17" and "0".

The first part is definitely not ISO8601.

Apparently, that is not the case, and thus the Eclipse versioning system is even more of a monstrosity.

1

u/netgu Sep 17 '20

I don't like the mixing of the two standards. What does the date add that isn't available when looking up the version? Do year rollovers work like major version bumps? Does the x.x.x portion work the same as other x.x.x version numbers?

Knowing something came from Nov, 2019 doesn't really give me any useful information. The version number will already link to commits that have that timestamp. And it isn't like November is the month every year we all work on one type of related feature or something.

1

u/[deleted] Sep 17 '20

They could do 3.9.1

3

u/[deleted] Sep 17 '20

That means something totally different.

3.9.1 is a patch to 3.9 to fix bugs.

3.10 is a new version with new functionality.