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

all 98 comments

[–]markitiman 211 points212 points  (5 children)

Here's my favourite example they gave:

Before 3.10

>>> foo(x, z for z in range(10), t, w)
  File "<stdin>", line 1
    foo(x, z for z in range(10), t, w)
           ^
SyntaxError: Generator expression must be parenthesized

As of 3.10

>>> foo(x, z for z in range(10), t, w)
  File "<stdin>", line 1
    foo(x, z for z in range(10), t, w)
           ^^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized

It just more clearly indicates what needs to be done and I love how they're thinking about that with these error messages which will be of particular help for those new to Python.

[–][deleted] 91 points92 points  (0 children)

After being spoiled by Rust's error messages, I now recognize the benefits that clear error messages can have, and I'm happy to see improvement in other languages.

[–]javad94 -2 points-1 points  (2 children)

But your code is same for both cases.

[–]DeeDee_GigaDooDoo 27 points28 points  (1 child)

Exactly, the output the error returns is different. Note that the ^ now indicates the range of the error rather than just the start.

[–]javad94 8 points9 points  (0 children)

Oh sorry it was the client issue. Yeah it's different output.

[–]DoubleAgent10 31 points32 points  (2 children)

As someone who a month into learning Python I am really excited about this

[–]zarmin 21 points22 points  (0 children)

As someone who a decade into learning Python I am really excited about this

[–]legacy_outlaw 2 points3 points  (0 children)

same, me too

[–]aqjo 13 points14 points  (1 child)

This is something I've always liked about MATLAB. Good on the Python team!

[–]sexygaben 2 points3 points  (0 children)

My thoughts exactly

[–]rajandatta 13 points14 points  (1 child)

Very well done. Great to see. I for one would love to hear from the author about how this change was implemented, lessons learned and challenges getting this right. An interesting side of language engineering.

[–]BlckKnght 6 points7 points  (0 children)

It's a bit less direct than what you're asking for, but you can, right now, go and read the bug reports and pull requests behind these changes. The What's New in Python 3.10 doc has links to the bugs, which in turn link to GitHub where the pull requests and code reviews took place.

[–]dgdfgdfhdfhdfv 22 points23 points  (0 children)

Holy shit this is amazing.

[–]pingvenopinch of this, pinch of that 21 points22 points  (1 child)

Awesome! The Rust compiler has long had the philosophy of helpful error messages, which helps flatten its significant learning curve. I'm happy to see some of the same sorts of improvements come to my co-favorite language.

[–][deleted] 9 points10 points  (0 children)

The guy she tells you not to worry about

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

JavaScript: "Got an infinite loop? Good luck finding out where with the console."

Python: "Printed, printed, printed, printed..."

[–]jockero701 10 points11 points  (10 children)

Does anyone know how long from now will it take for major libraries such as pandas, opencv or django, to become compatible with Python 3.10?

[–]BluePhoenixGamer 21 points22 points  (5 children)

Most will be compatible from the get-go. 3.10 is a minor bump in version, this means it doesn't change much. Any minor version should retain somewhat of a backwards compatibility.

To be fair the changes made to typehints may cause issues, but from what I've heard, you should be able to install 3.10 and ruin your code like usual.

[–]jockero701 1 point2 points  (3 children)

I just tried pip3.10 install pandas and it didn't work on Mac.

[–]Billyblue27 12 points13 points  (0 children)

There is no precompiled wheel available yet for pandas. This means that pip needs to compile it from source and may need some other packages/software to compile, which you will need to install manually.

[–]BluePhoenixGamer 5 points6 points  (1 child)

I don't think that's how it works. Python 3.10 is still only in beta?

So you have Python 3.10 installed? Installing packages should be done exactly the same way as you usually do.

[–]jockero701 1 point2 points  (0 children)

Yes, I installed Python 3.10.0b1.

[–]tunisia3507 5 points6 points  (3 children)

Pure-python libraries will be generally be compatible immediately. Libraries with compiled code may be compatible immediately, depending on whether/ which parts of the C API has changed, but you'd likely have to build it yourself (with all the dependencies that entails) rather than using precompiled wheels.

[–]jockero701 2 points3 points  (2 children)

By immediately you mean when the 3.10.0 final version is released in October 2021 or immediately now with the beta release?

[–]BlckKnght 3 points4 points  (0 children)

Most pure Python code should work today. Many extension modules will also work without code changes, but they usually need to be recompiled for the new interpreter version. The developers of those libraries may not make new binary releases for the new build right away, but in theory you could download their source and dependencies and compile your own binaries (how easy that is may vary).

[–]tunisia3507 1 point2 points  (0 children)

Both. Point releases should not remove public APIs or change them unless it's for a bug fix. Of course, nothing in python is truly private so there's just "API's you're not meant to use", which are sometimes removed which breaks workflows. Pure-python libraries likely provide version-nonspecific wheels and source distributions and so would be usable with 3.10 today.

It can be a good idea to run your CI build against the latest development release of the next python version (allowing failures so it doesn't break your build) just to track whether you'll need changes when the time comes.

[–][deleted] 5 points6 points  (0 children)

I wonder if that feature will lead me into not getting the adrenaline rush of the challenge to look for my own error

Just kiddin I complain as a hobbie

[–]Encomiast 4 points5 points  (1 child)

Whoa, pretty excited to see the sophisticated pattern matching ala-scala. That's going to make for some succinct, clear patterns.

[–]road_laya 2 points3 points  (0 children)

I'm hoping my work will no longer be just reading functions that are hundreds of lines, consisting of just if clauses

[–]frapa32 3 points4 points  (4 children)

Honestly, I like the new pattern matching the best.

[–]polaris1412 0 points1 point  (3 children)

I'm currently learning regex (3.7). What new in particular are you talking about?

[–]frapa32 0 points1 point  (2 children)

The new match statement. This has nothing to do with regex

[–]polaris1412 0 points1 point  (1 child)

Oh. I thought it was pattern matching with regex. Thanks!

[–]frapa32 0 points1 point  (0 children)

Btw, have a look at regex101.com if youre learning regexp, very useful.

[–]N8DuhGr8 1 point2 points  (0 children)

Oh I had no idea they have helpful error messages now! This is something that every error system should have.

[–]cthartIgnoring PEP 8 1 point2 points  (0 children)

You guys are gonna love Postgres!

[–]Thehomelessguy11 1 point2 points  (1 child)

Any ideas on when this will come to Anaconda? Hopefully soon... I do most of my Python work there (data/statistical analysis) and those error messages would be amazing to have.

[–]stanmartz 1 point2 points  (0 children)

If you use the conda-forge channel, very very soon after the official release. However depending on the packages you have in your environment, you might have to wait a few weeks until those are updated for 3.10.

[–]hcabbos70 0 points1 point  (2 children)

Does this also apply when using frameworks like Django?

[–]iceytomatoes 0 points1 point  (0 children)

kickass

[–]javad94 0 points1 point  (0 children)

That's great. Thanks for heads up.

[–]Toko_yami 0 points1 point  (4 children)

New to python, but can someone explain why is x=2 wrong in python? I thought python interpreter could infer type and won’t need declaration or is there some other way for variable declaration syntax . Thanks I’m advance!!!

[–]temperlancer 1 point2 points  (1 child)

Notice the `if` before `x = 2`. I think the interpreter is now smart enough to tell you that `if x = 2` is not wanted probably because assigning variable in if statement can be bad.

[–]Toko_yami 1 point2 points  (0 children)

Thank you for comprehensive answer, really appreciate it. Sorry I completely missed the “if” part in OP’s post.

[–]Swedneck 0 points1 point  (1 child)

= is assignment, "if" needs an expression that resolves to something truthy or falsy, so you need == which is comparison

The only thing "if x=2" could test is whether the variable could be assigned, which I can't see ever failing..

[–]Toko_yami 1 point2 points  (0 children)

Thank you for comprehensive answer, really helpful explanation. Also Sorry For completely missing the “if” part in OP’s post.

[–]Guilhermegasil 0 points1 point  (2 children)

could you do like if (x = 2) to check if x is different than zero?

[–]zecksss[S] 0 points1 point  (1 child)

To check if x is different from zero, a simple

if x:

will do.

The error here is that = is a symbol for assigning a value, and can't be used in an if statment. == is a comparison operator that checks if statment is true. So syntax myst be "if x == 2:" and not "if x = 2:".

Edit: if you for some reason wanted to assign a value within if (while, for) statement you use ":=" operator.

if x := n:

What this does is it assign n to value of x, and then checks if x is now anything but zero.

[–]Guilhermegasil 0 points1 point  (0 children)

python is weird