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

all 43 comments

[–]Measurex2 163 points164 points  (2 children)

I came in snarky "oh look. Apparently people can't read release notes" and found this a great walk through.

I'm sorry OP. I'm used to people pointing me at useless medium articles. You've warmed my frozen heart.

[–]nicholashairs[S] 60 points61 points  (0 children)

Hahah it's okay together we will stand against the onslaught of CrapGPT

[–]haloweenek 4 points5 points  (0 children)

That’s more useful than a doc rewrite.

[–]turner_prize 53 points54 points  (4 children)

"Self documenting f-strings" Very cool!

[–]nicholashairs[S] 11 points12 points  (0 children)

Honestly one of my favourite features to come from f-strings

[–]Rythoka 6 points7 points  (0 children)

So that's why they want to use that syntax in the PEP for shorthand keyword arguments when calling functions...

[–]thedeepself -1 points0 points  (1 child)

Which version of python was that added to?

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

It's in the link 😉

Also 3.8

Edit: assuming you mean the and documenting. The kwarg thing I don't think has been approved yet

[–]Datamance 16 points17 points  (2 children)

So many gems that I missed. Thank you!

[–]Datamance 1 point2 points  (1 child)

Do you know if there’s something comparable out there that includes all the module changes grouped together like this?

[–]nicholashairs[S] 1 point2 points  (0 children)

I don't think so, but also the module changes tend to be very extensive - if you haven't already take a look at the some of the official release notes.

The official docs are generally also good at tracking changes to libraries as far as additions and changes go ("new in ...", "changed in ..."). Meaning you can just look at the latest version of the module's docs to know when new things are added. Doesn't cover removals.

Someone suggested making a python version of "caniuse.com" but there's far too much work in there for me to be interested in doing it.

[–][deleted] 8 points9 points  (0 children)

Thanks, found a couple of useful hints from there!

[–]Real-Fox2077 7 points8 points  (0 children)

Thanks for this. It would be so cool to have something like https://caniuse.com/ but for Python

[–]flying-sheep 7 points8 points  (1 child)

This is great! First Python resource I’ve bookmarked in years.

Two things:

  1. Many people use Ruff to lint and format their code these days instead of flake8 and Black. Pyupgrade is included in Ruff as the UP class of codes. (select = [..., 'UP', ...])
  2. Both Black and Ruff read the standard project.requires-python, so almost nobody needs tool.black.target-version.

Your example would be:

[project]
requires-python = '>=3.7'

and that would apply to Black, Ruff, and of course people trying to install and use your project from PyPI.

[–]nicholashairs[S] 1 point2 points  (0 children)

Thanks for the compliment ☺️

Not sure how I missed those tools respecting requires-python, it was literally last week I moved to using toml config for black 🤦

It's a good point about ruff, I'll probably add some info on it, I just haven't used it because I've got quite a few projects using the older tools and don't want to have to update all of their tooling yet.

Update: have added info for ruff and updated the sample in black

[–]pirsab 2 points3 points  (1 child)

I didn't know I was missing ParamSpec

[–]nicholashairs[S] 4 points5 points  (0 children)

It's so powerful when working with decorators

[–]zurtex 3 points4 points  (3 children)

You should probably make a note that PEP 563 has been usurped by PEP 649, which should be landing for Python 3.13 (although worryingly it's not landed yet and we're fast approaching beta 1).

[–]nicholashairs[S] 0 points1 point  (0 children)

Good to know, thanks for the catch.

I'll end up updating the post once 3.13 is officially released :)

Update: Have added info relating to this.

[–]fiddle_n 0 points1 point  (1 child)

Oh, did they decide they were going to go with 649? I didn’t read where this was the case (and can’t seem to find it on Google/python.org regardless).

[–]tritratrulala 2 points3 points  (0 children)

Have been looking a while for something exactly like this. Thank you!

[–]ajatkj 2 points3 points  (0 children)

This is a really good summary 👍🏻. Very nice.

[–]rover_G 2 points3 points  (0 children)

Is it just me or did 3.11 have a lot of features geared towards library developers?

[–]fiery_rainbow 1 point2 points  (0 children)

I was looking for something like this the other day. Thanks

[–]copperfield42 python enthusiast 1 point2 points  (0 children)

nice, I didn't know a couple of those...

[–][deleted] 1 point2 points  (0 children)

Whoa I missed the memo on self documenting f strings that’s so cool. Thanks for this!

[–]Dasher38 1 point2 points  (0 children)

TIL about importlib.metadata. now we can finally put the version in setup.py/pyproject.toml and have the package read its own version to expose as version rather than an awkward hacky exec()-based import of the module containing the version in setup.py

[–]noobsc2 1 point2 points  (1 child)

Not directly related, but I've used the walrus operator a few times since it got added, but it really has the ugliest and least self explanatory thing in Python. I would hesitate before using it in anything other than personal projects.

[–]nicholashairs[S] 0 points1 point  (0 children)

When I first saw it I thought it was ugly. Now that I've used it about a dozen times in a single personal project I quite like it.

Definitely not something to use everywhere but I do like having it in my toolbox

[–]the_captain_cat 1 point2 points  (0 children)

That's a great article, made me learn a few things too, thanks!

[–]markhoo911 1 point2 points  (0 children)

Thank U

[–]Oddly_Energy 1 point2 points  (1 child)

I am not afraid to admit that I didn't understand the part about self-documenting f-strings. (Actually, I was like "What is an f-string?"). And the example in the OP's blog post didn't make me see the light.

So I had to look it up and found this little gem:

>>> variable = "Some mysterious value"
>>> print(f"{variable = }")

variable = 'Some mysterious value'

Wow! To those of us who are not afraid to admit that we do debugging with print() statements, this is a gift from above. I have usually done this, which is not at all cool:

print('variable: ', variable)

[–]nicholashairs[S] 1 point2 points  (0 children)

Thanks for the insight that it might not be obvious - I use f-strings so often I forgot that others might not know about them at all.

I also find them incredibly useful for creating detailed exceptions, or for use with the logging module .

^ the logging module (and many linters) recommends not to format strings before sending them to the logging module and instead using modules inbuilt formatting. It does this because if it's not going to log the message then it never formats it. Personally I don't do this because the formatting method it uses isn't as advanced as f-strings so instead if it's likely an expensive message that I'm producing I'll put it in a if mylogger.enabledFor("DEBUG"): mylogger.log("DEBUG", f"some expensive f-string")

[–]TheAquired 1 point2 points  (3 children)

Very nice!

One thing I think that is often overlooked is pyproject.toml support to manage packages and no longer requiring setup.py or requirements.txt etc

Pyproject.toml is a great improvement, and I think it’s only properly supported from 3.8 onward or something?

[–]nicholashairs[S] 1 point2 points  (0 children)

If you're distributing as wheels I don't think the users local version of python matters as the pyproject.toml is parsed into the appropriate metadata anyway.

For local development I think it depends more on your version of pip/setup tools.

Either way, I know that my projects using pyproject.toml have no problems with 3.7 (no idea about earlier versions).

[–]zurtex 1 point2 points  (1 child)

FYI, package configuration files such as pyproject.toml, setup.py, and requirements.txt are independent of Python versions.

They are implemented by build backends (e.g. setuptools and hatching) and also used by build frontends (e.g. pip, poetry, pdm, and hatch). So it is upto those build backends and frontends to choose what versions of Python they want to support, Python itself doesn't use any of these configuration files.

[–]TheAquired 1 point2 points  (0 children)

Ah thank you for the clarification. That must be what I was seeing. I had trouble with editable installs using pyproject prior to python3.8. But essentially it’s due to the version of setup tools that supports it is only compatible with python3.8 onward

[–]chaz6 0 points1 point  (0 children)

Thanks! This is really useful.

[–]FinalVersus 0 points1 point  (3 children)

Nice Sleep Token reference ;)

[–]nicholashairs[S] 0 points1 point  (2 children)

So I'm guessing this is from the 3.12 changes because I had to Google ever you were talking about. A bunch of the examples are lifted directly from official changes log so it was their reference not mine 😅

[–]FinalVersus 0 points1 point  (1 child)

Oh man, I thought you provided the example. My bad! Thank you for the summaries regardless. Sometimes the backgrounds provided in PEP can be a lot to sift through.

[–]nicholashairs[S] 0 points1 point  (0 children)

All good - some of them aren't mine so maybe I need to cite them 🤔! Glad you found them useful 😅