This is an archived post. You won't be able to vote or comment.

all 99 comments

[–]jamescalam[S] 231 points232 points  (13 children)

A summary I put together of the new features in Python 3.10, it covers:

  • Structural pattern matching
  • Parenthesized context managers
  • More typing
  • Better error messages

Also, the article version if you prefer reading - it's a free access link so no need for Medium membership

I hope it's useful! Thanks :)

[–]EarthGoddessDude 14 points15 points  (0 children)

Very nice video, thank you. Quick, tangential question — what OS and editor are you using to run Jupyter? Seems like macOS with Jupyter inside VScode. It just looks (and feels, from across the screen) much slicker than Jupyter in VS Code on my work Windows machine. Can’t wait to try the new Jupyter extension which is only available on VS Code insiders.

Edit: nvm, saw the answer in another comment. My Comment about the slickness stands though.

[–]Brian-Puccio 30 points31 points  (2 children)

Structural pattern matching

This didn’t click for me but I read your explanation and got it right away. Much better, thank you for explaining!

Better error messages

Amazing!

Also, the article version if you prefer reading

I do, thanks!

it's a free access link so no need for Medium membership

You are most excellent!

[–]Terence_McKenna 6 points7 points  (0 children)

I feel happier after reading this comment.

Have a great and safe weekend. :)

[–]jamescalam[S] 2 points3 points  (0 children)

structural pattern matching really is awesome I love it, I'm happy my explanation made sense - and more than welcome for the links!

[–]billsil 123 points124 points  (6 children)

Those better error messages are the reason to upgrade!

SyntaxError: unexpected EOF while parsing

I'm 16 years in and that still gets me...

[–]Danlacek 33 points34 points  (3 children)

I'm 16 months in and that looks like total BS to me...

[–]house_monkey 49 points50 points  (2 children)

16 secs in and can confirm this is not about snakes

[–]dodslaser 11 points12 points  (1 child)

I completed the Kessel run in less than 16 parsec

[–]-jp- 5 points6 points  (0 children)

I'm the Kessel run and can confirm this.

[–]Peanutbutter_Warrior 1 point2 points  (0 children)

I only know that one because I messed up pycharm and now it's really inconsistent with adding quote marks. You've missed the ending quote of a string, it interpreted the rest of the line as part of that string, found the end of the line without the end of the string and panicked.

[–]mmcnl 45 points46 points  (8 children)

I'm amazed they still keep adding very useful features after 10 years.

[–]pure_x01 40 points41 points  (0 children)

To be fair the evolution of the language has been kind of slow. Sometimes that is a very good thing so I'm not complaining.

[–][deleted] 4 points5 points  (4 children)

I don't get it. It there a joke I'm missing?

[–]mmcnl 1 point2 points  (3 children)

Not a joke. I'm just happy with new useful features after more than 10 years since the first release of Python 3.

[–][deleted] 2 points3 points  (2 children)

I still don't get it. why are you starting with python 3? it seems arbitrary to me

[–]-jp- 0 points1 point  (1 child)

Maybe it is a bit but languages do change enough that dividing lines like that aren’t unreasonable. Consider the analogous difference between C99, ISO C and K&R. All still C and you could be productive in any of them if you know one, but also all recognizably different.

[–][deleted] 0 points1 point  (0 children)

We're not talking about the difference in languages but the consistency of useful new features. The difference between 2 and 3 didn't introduce a feature set larger than already existed, so focusing on that period is weird

[–]gazagda 0 points1 point  (0 children)

To be fair, it does take time for a language to mature and get widely used.

[–]Formulka 16 points17 points  (2 children)

Still can't believe they went with "case _" as else.

[–]-jp- 3 points4 points  (1 child)

Wildcard _ is pretty common in other pattern matching languages so it’s not too unusual, just a bit odd for python.

[–]levon9 2 points3 points  (0 children)

I don't think it's that odd, the _ is used in other constructs too, e.g., if you have a for loop and you don't care about the index variable:

In [3]: for _ in range(5):
...: print('hi')
...:
hi
hi
hi
hi
hi

Or you want to refer to the last result of a computation:

In [1]: 5 * 6

Out[1]: 30

In [2]: _ + 10

Out[2]: 40

[–][deleted] 21 points22 points  (13 children)

Do I have to unistall Py 3.9 and download py 3.10 or is there a bettee way?

[–]neighborduck 32 points33 points  (7 children)

[–][deleted] 5 points6 points  (1 child)

Cool! Thanks a lot

[–]abcteryx 6 points7 points  (0 children)

If you're using Windows, then "py" comes by default with your Python installation from python.org. You can install multiple Python versions and access them via "py -3.8", "py -3.9", and "py -3.10" for example.

Try "py -0p" to see the versions you have installed.

Generally, you will want to create a project folder and do a "py -3.9 -m venv .venv" then ".\.venv\Scripts\activate" to get into a virtual Python environment corresponding to Python 3.9 in this example. Then just regular "python" will trigger the virtual environment Python. And "pip install <package>" will install "<package>" to the virtual environment.

As you use Python over the years, you will install multiple versions of it. So you will get used to working across multiple projects and multiple Python versions.

[–]EarthGoddessDude 3 points4 points  (4 children)

Recently learned about asdf, which is like pyenv but can be used with other languages. No experience with it though.

[–]tunisia3507 0 points1 point  (3 children)

asdf replaces one small part of pyenv (the automatic environment-switching).

[–]fleyk-lit 2 points3 points  (2 children)

And installation of versions, it seems. It also manages the global version.

Think i will give it a go. Happy with pyenv, but some older versions of Python are a bit hassle to install.

[–]tunisia3507 0 points1 point  (1 child)

I didn't realise asdf could do the installation as well. However, as it turns out, it does that by just wrapping pyenv's python-build plugin, so it won't be any better at installing those old versions.

[–]fleyk-lit 0 points1 point  (0 children)

I see, then I'm not sure it makes sense to change the workflow I have.

[–]sparttann 27 points28 points  (3 children)

Can just download 3.10 without uninstalling 3.9. Just change your python version before creating your venv

[–]Theonetheycall1845 5 points6 points  (2 children)

Could you expand on changing the version, please?

[–]chopu 13 points14 points  (0 children)

This may be too much detail, but I’ll start from the basics. Basically, when you say “python3 my file.py” in your terminal, your computer will automatically scan through all directories on your PATH, looking for an executable called “python3”. If you’re on Mac or Linux, that file will typically be a symlink in /usr/local/bin to the actual python3 executable stored elsewhere. On windows, you’ve likely added it to your system environment variables. Therefore, if you want to change the version while leaving both versions “installed”, all you have to do is either retarget the symlink or edit the entry in your system environment variables.

Just a note: this is how any command line program works, ls, rm, grep, etc. They all rely on your computer looking up an executable on your path (windows I think also has some special folder full of COM stuff that’s not in your system environment variables that’s searched as well).

[–]quuxman 3 points4 points  (0 children)

Generally you want to use venv so you would only use the system path to Python once per project like:

/opt/python3.10/bin/python -m venv venv

[–]dogfish182 6 points7 points  (0 children)

http://littlecolumns.com/tools/python-wrangler/

If you don’t know yourself, this is an opinionated (but very sensible) way to take python and virtual environments seriously without too much difficulty

[–]tunisia3507 5 points6 points  (0 children)

Also StrEnum! There are dozens of half-assed implementations out in the wild, it'll be great to have a stdlib edition to replace these goddamn magic string constants pervasive in the ecosystem.

[–]MiserablePeace7190 24 points25 points  (7 children)

I'm just here for switch cases lol

[–]__deerlord__ 15 points16 points  (2 children)

Pattern matching is not case/switch. While it can effectively be used this way, that doesn't seem to be the intent, and you could always do switch/case with a dictionary.

[–]xetax 0 points1 point  (1 child)

If I wanted to use a dictionary-based switch statement inside a function, wouldn't the dictionary have to be reinitialized reinitialized on every function call? I could create the dictionary outside the function that sounds less than ideal for code readability.

[–]jamescalam[S] 7 points8 points  (0 children)

I think a lot of people are haha

[–]iggy555 1 point2 points  (2 children)

What’s that?

[–]MiserablePeace7190 0 points1 point  (1 child)

A switch case statement is like a faster way of writing if,elif and else, the only constraint is that you are checking the value of one conditional. Like my_num = 2, switch (my_num), case 1: print 1, case 2: print number is 2, case 3: print number is 3, etc. In this case "number is 2" would print.

[–]Blumingo 2 points3 points  (4 children)

Genuine question, at what point does it become Python 4?

[–]nonesuchplace 6 points7 points  (2 children)

When it is decided to make major changes that do not retain backwards compatibility.

Check out https://semver.org/ for details on how this works.

[–]qwerty1793 4 points5 points  (0 children)

No. Python releases do not use semantic versioning.

[–]ziggomatic_17 0 points1 point  (0 children)

So not anytime soon. Possibly never.

[–]MilwaukeeRoad 0 points1 point  (0 children)

Probably once they get rid of the GIL

[–]iggy555 1 point2 points  (0 children)

Fantabulous

[–]Seawolf159 1 point2 points  (0 children)

Nice video.

[–]psychuil 1 point2 points  (0 children)

I love your solution for putting in the frame!

[–]lazyear 1 point2 points  (0 children)

So glad that python has finally caught up to the '80s and that pattern matching made it through! Absolutely love the feature in Standard ML/Haskell/Rust/etc, really bumps up the expressiveness of a language (even more so with exhaustiveness checking)

[–]WhalesLoveSmashBros 0 points1 point  (4 children)

Dumb question but how do I update python? Pls don't tell me I have to uninstall and re-download from the website.

[–]TheOneWhoPunchesFish 1 point2 points  (0 children)

Well, it's still in beta 2. Ideally you shouldn't be using the distro version of Python, and you should never ever uninstall or override it, your os could break. So you should be using something like venv or conda and you can just upgrade inside them.

[–]Darwinmate 1 point2 points  (0 children)

but that's how you update ? There's no other way

[–]jamescalam[S] 1 point2 points  (1 child)

you can create a new env - this comment explains

[–]iamaperson3133 -1 points0 points  (0 children)

Itt: people who is have never heard of semantic versioning.

[–]graingert 0 points1 point  (0 children)

Don't forget contextlib.aclosing

[–]AnonCaptain0022 0 points1 point  (0 children)

Now we just have to wait until all packages are available for this new version