Thanks for all the amazing content you share with us... Pretty cool that you get to work in core python projects and even talking to Guido! Cudos for you! Looking foward to use your pre-commit library, im still figuring it out.. Greetings from Chile!
Yeah, it's very nice of you to explain this, thanks. Cuts down the time to research it oneself. You'll have to do it for professional reasons anyway, I guess, so mighty fine to spend the extra time, make a video, and save some strangers collective days of tedium.
2:13: infinitely nestable f-strings 9:16 the modules that are going away: 'distutils' module; 11:48: the 'imp' module 12:45 type variables/parameters/aliases (allows Generics to be specified easier)
You did the $ variables in pdb correctly, they stay between stack changes, not continuing execution (they are cleared then). batched doesn’t error, you were unpacking it assuming it returned the same number each time. For its use case (batching items for multiprocessing), that’s exactly what you want and it’s a benefit over the existing helpers. Just don’t unpack assuming identical batch sizes. :)
Was this use case really the primary reason for its inclusion in the standard library? I've done this using grouper from more_itertools for years, there is also so much more additional nice functionality in that package that it would be nice to have had a bit more of it included in the standard library.
Oooh that's what I was wondering about as well. Seeing something that can help do batches for me (without weird math to get me there) is really handy, since I typically use a whole batch at a time rather than unpacking! Neat!
To me, the point of itertools.batched _is_ that the final "element" can contain fewer elements! Many algorithms are memory intensive, so being able to cap the number of elements for each batch means you can limit how many subelements are handled, rather than being a zip-replacement. So rather you would have: for batch in itertools.batched(it, 2): if len(batch) == 1: process_one(batch[0]) elif len(batch) == 2: process_two(batch) else: continue Or something smarter. In machine learning fields, this is a common way to handle training data, and while there are other tools for this there, it is nice to have a python implementation for this. As recently as a week before the release of python 3.12 I had to install the more itertools package to get this function for a project.
This new generics syntax and the type keyword is just a shocker honestly. Couple more versions - and the language becomes non-recognizable to people used to 3.7 or something :)
You are making amazing videos and I'm watching them not for fun but as an actual short/dense overview of new features or some tweaks and tricks. I have learn a lot from your videos. I appreciate your work.
Removal of distutils can hurt only in one circumstance - where you don't have access to pip at all, and you're stuck with whatever standard library can provide to you, either as learning excercise or your boss have panic attack when hears about anything 'third-party' :)
Great video! The function annotations look... goofy. However I'm glad to hear that list comps (and I assume dict comps as well, but I'd have to look) got a speedup that seems relatively trivial!
I can’t say I understood a lot of this, but it was very good background chatter to put on while mindlessly programming, so thank you for helping me focus haha
Generics are now more in line with those in Java and Rust, which is nice. Does isinstance work if you declare something as that type explicitly? Like `type MyType = int; a: MyType = 2; isinstance(a, MyType)`?
Better typing-syntax is great, we want more typing but less typing. Similarly improved error messages help with learning and sleep deprivation. The new itertool change also allows doing some very satisfying but pretty cursed stuff. Just have a list that contains lists of anonymous functions and some structure of values, in alternating fashion, and call those functions on the values in some meaningful way. and now this one line of code runs sets of functions on a list of values, then a different set of functions on a different list of values, and so on. You will feel so smart when you get it to work properly. This can compeletely replace classes and I bet everyone reading the code is throughoutly impressed. Or you can use it to parse a list in chunks like a normal person.
@@RedShipsofSpainAgain It was not a bug. It was 2 unnecessary variables exposed in module namespace because it was required in many functions inside the module, that's why it was kept global, No one thought that somebody will use it, but few of them are using it. Now we have added a deprecation warning for the same.
@princeroshan4105 Ahh ok thanks for explaining. But why were only 2 months needed? Seems like an arbitrary number of months to require. Couldn't they have just added the other 10? Why stop at 2 months? Why not 3? Or 7?
Great content as always! What about PEP 684? Looks like it's listed as one of the major changes in the release notes for 3.12 and sounds quite cryptic to me, I'd love a video about this
i was just wondering what was the use case for nested f-strings? I feel like it is satisfying to allow any combination of quotes in nested expressions but I can't think of use case for nested ones.
My guess would be that now you can have an uggly general formatting string bound to a symbol, expand it with one fstring and then call that new fstring. I have not tried this, but my idea would look something like: Charlie=“charlie_stateA” f’{f’{Charlie}_3’}’ to exapand the variable charlie_stateA_3 Basically what this allows is manipulating the command or symbol the outer f-string will expand. It’s kind of a macro, and does what eval would do. Just thinking this makes my head hurt a bit, so I’m not sure if I will even bother trying it. But you might be able to “generate” an anonymous function with combining different symbols, and then evaluate that with-in the larger f-string. Like you could use a symbol to determine what lambda-function you will use to filter a list, and just do that inside an f-string. So in short, think of the most cursed way to use eval you can imagine. Now you can do that all within a single f-string. I feel very very sorry for anyone who is better of having this feature available, but for sake of completeness it makes sense to add.
...oof... the nested f-string is nice, but seems to me it'll get pretty messy very quickly. Makes me wonder if you could pull a walrus op inside f-string... gonna play with 3.12 later This is oddly interesting behavior. Running below... arr = '1 1 2 1'.split() f"nums are: {f'{" ".join([str(y) for _ in arr if (y:=int(_) + 3) == 5])}:{" ".join([str(y) for _ in arr if (y:=int(_) +3) == 4])}'}" Returns below... 'nums are: 5: 4 4 4' Code looks clunky, hard to read, & quotations seem to be very touchy when switching between single & double marks. Tested this in pre release 04 of version 3.12 but it works.
Some of these like the f string and generic type is really hard to read. Just wondering what impact will it have in libraries like Pydantic. Btw, you are one of the coolest person in the Python community.
Line 269 of pdb.rst after commit 7db9d37... in issue 103694 says: "The*convenience variables* are cleared when the program resumes execution so it's less likely to interfere with your program compared to using normal variables" Looks like this is the reason it wasnt defined after you resumed :)
Really enjoyed the video. Pretty excited by @override and typed kwargs. And pre-commit now in cpython, wow this is win! It's fun that pdb became php xD
These hipsters introduce new typing shit, that doesn't even work with builtins like isinstance. It's ridiculous. As if bunch of javascript devs flooded core and started making decisions.
Thanks for not trimming it down for the stupid youtube algorithm.
This was great, I look forward to getting to play with these in 3 years when python 3.12 is a few months from EOL
@DavidDellsperger glad to see familiar faces here ...
Thanks for all the amazing content you share with us... Pretty cool that you get to work in core python projects and even talking to Guido! Cudos for you! Looking foward to use your pre-commit library, im still figuring it out.. Greetings from Chile!
Yeah, it's very nice of you to explain this, thanks. Cuts down the time to research it oneself. You'll have to do it for professional reasons anyway, I guess, so mighty fine to spend the extra time, make a video, and save some strangers collective days of tedium.
def x[T, U, V](y: U, z: V) -> list[T]: pass
*holds head*
2:13: infinitely nestable f-strings
9:16 the modules that are going away: 'distutils' module; 11:48: the 'imp' module
12:45 type variables/parameters/aliases (allows Generics to be specified easier)
You did the $ variables in pdb correctly, they stay between stack changes, not continuing execution (they are cleared then).
batched doesn’t error, you were unpacking it assuming it returned the same number each time. For its use case (batching items for multiprocessing), that’s exactly what you want and it’s a benefit over the existing helpers. Just don’t unpack assuming identical batch sizes. :)
Was this use case really the primary reason for its inclusion in the standard library? I've done this using grouper from more_itertools for years, there is also so much more additional nice functionality in that package that it would be nice to have had a bit more of it included in the standard library.
Oooh that's what I was wondering about as well. Seeing something that can help do batches for me (without weird math to get me there) is really handy, since I typically use a whole batch at a time rather than unpacking! Neat!
To me, the point of itertools.batched _is_ that the final "element" can contain fewer elements! Many algorithms are memory intensive, so being able to cap the number of elements for each batch means you can limit how many subelements are handled, rather than being a zip-replacement. So rather you would have:
for batch in itertools.batched(it, 2):
if len(batch) == 1:
process_one(batch[0])
elif len(batch) == 2:
process_two(batch)
else:
continue
Or something smarter. In machine learning fields, this is a common way to handle training data, and while there are other tools for this there, it is nice to have a python implementation for this. As recently as a week before the release of python 3.12 I had to install the more itertools package to get this function for a project.
This new generics syntax and the type keyword is just a shocker honestly. Couple more versions - and the language becomes non-recognizable to people used to 3.7 or something :)
Yeah - that also hit me as looking just "wrong" - but I'll get used to it I guess...
nah, just a few touches
Basically generics syntax is now closer to what it is in many other languages. What a shocker
Just don’t use the syntax unless it’s fun.
I love the fact that Anthony mostly wings his videos! Very cool ♥
Appreciate the dissect on what's comin. Neat find on the NUL byte too
You are making amazing videos and I'm watching them not for fun but as an actual short/dense overview of new features or some tweaks and tricks. I have learn a lot from your videos. I appreciate your work.
Removal of distutils can hurt only in one circumstance - where you don't have access to pip at all, and you're stuck with whatever standard library can provide to you, either as learning excercise or your boss have panic attack when hears about anything 'third-party' :)
Great video! The function annotations look... goofy. However I'm glad to hear that list comps (and I assume dict comps as well, but I'd have to look) got a speedup that seems relatively trivial!
Thanks for the overview Anthony, a fun and insightful video as always!
Amazing content. I love to watch your videos. You are so informative. Thanks for doing this. I appreciate your efforts. 🙏
Unpacking of the TypedDict is a blessing
I can’t say I understood a lot of this, but it was very good background chatter to put on while mindlessly programming, so thank you for helping me focus haha
that's just amazing.. thanks for taking out time and giving an overview of cool features of 3.12
Quite like the Generic types overhaul. I gave a wry chuckle and wondered when Python would become Scala 😏
Generics are now more in line with those in Java and Rust, which is nice.
Does isinstance work if you declare something as that type explicitly? Like `type MyType = int; a: MyType = 2; isinstance(a, MyType)`?
no. type hints aren't part of the runtime like that they're mostly just comments
In ISO 8601 monday is the start of the week + Week with weekday notation e.g. 2023‐W32‐1 is a monday
Thank goodness for that. No offense, but I can't stand the week starting on a Sunday!
I like the override decorator. Explicit is better than implicit, right? 😊
I'm totally on board with you!
Informative and engaging, thanks for uploading. I love the nice error messages.
Thanks for the video! Love it! Love your style!
The features not so much tho
Can someone add timestamps? A tldr and a way to jump into detail is really helpful
Thanks for the video, I waited for override decorator, as in my project we wrote it by our own. Minus one shitty func in our repo)
Better typing-syntax is great, we want more typing but less typing. Similarly improved error messages help with learning and sleep deprivation.
The new itertool change also allows doing some very satisfying but pretty cursed stuff. Just have a list that contains lists of anonymous functions and some structure of values, in alternating fashion, and call those functions on the values in some meaningful way.
and now this one line of code runs sets of functions on a list of values, then a different set of functions on a different list of values, and so on. You will feel so smart when you get it to work properly. This can compeletely replace classes and I bet everyone reading the code is throughoutly impressed.
Or you can use it to parse a list in chunks like a normal person.
I added those enums in calendar 😁, that was I guess my first PR to Cpython.
Thanks, man! 😃
Great work! Keep contributing.
Good job! Kinda of amazing that Python has had this bug for 23 years. How did no one think to fix this sooner??
@@RedShipsofSpainAgain It was not a bug. It was 2 unnecessary variables exposed in module namespace because it was required in many functions inside the module, that's why it was kept global, No one thought that somebody will use it, but few of them are using it. Now we have added a deprecation warning for the same.
@princeroshan4105 Ahh ok thanks for explaining. But why were only 2 months needed? Seems like an arbitrary number of months to require. Couldn't they have just added the other 10? Why stop at 2 months? Why not 3? Or 7?
Instead of /dev/stdin you can just not give tokenize any file argument and it'll default to stdin
Great content as always! What about PEP 684? Looks like it's listed as one of the major changes in the release notes for 3.12 and sounds quite cryptic to me, I'd love a video about this
most people don't care -- subinterpreters is mostly for embedding python
hyped for the vid! chapters would be super helpful
I'll edit them in at some point!
@@anthonywritescodedon't forget about us. I'm saving this video for future reference
❤ for casual inheritance diss ❤❤
really enjoyed this! thanks for all your videos 🙏🙏
Always love these, so I know what to tell my colleagues about the new python version!
i was just wondering what was the use case for nested f-strings? I feel like it is satisfying to allow any combination of quotes in nested expressions but I can't think of use case for nested ones.
My guess would be that now you can have an uggly general formatting string bound to a symbol, expand it with one fstring and then call that new fstring.
I have not tried this, but my idea would look something like:
Charlie=“charlie_stateA”
f’{f’{Charlie}_3’}’ to exapand the variable charlie_stateA_3
Basically what this allows is manipulating the command or symbol the outer f-string will expand. It’s kind of a macro, and does what eval would do.
Just thinking this makes my head hurt a bit, so I’m not sure if I will even bother trying it. But you might be able to “generate” an anonymous function with combining different symbols, and then evaluate that with-in the larger f-string. Like you could use a symbol to determine what lambda-function you will use to filter a list, and just do that inside an f-string.
So in short, think of the most cursed way to use eval you can imagine. Now you can do that all within a single f-string. I feel very very sorry for anyone who is better of having this feature available, but for sake of completeness it makes sense to add.
Cool kb. What is it? freestyle pro?
There is no mention of the changes to GIL in py3.12 in this video.. why? It seems like quite a change, would like to hear your insight on it.
that's not until 3.13 at the earliest
...oof... the nested f-string is nice, but seems to me it'll get pretty messy very quickly. Makes me wonder if you could pull a walrus op inside f-string... gonna play with 3.12 later
This is oddly interesting behavior.
Running below...
arr = '1 1 2 1'.split()
f"nums are: {f'{" ".join([str(y) for _ in arr if (y:=int(_) + 3) == 5])}:{" ".join([str(y) for _ in arr if (y:=int(_) +3) == 4])}'}"
Returns below...
'nums are: 5: 4 4 4'
Code looks clunky, hard to read, & quotations seem to be very touchy when switching between single & double marks. Tested this in pre release 04 of version 3.12 but it works.
Some of these like the f string and generic type is really hard to read. Just wondering what impact will it have in libraries like Pydantic.
Btw, you are one of the coolest person in the Python community.
Great video, I learnt so much!
I love pyupgrade, i use it regularly
Generics is a little scary looking!
With the new f-string parsing we can finally write php in python 🙃
Thanks dude what a great content ❤❤❤
The batched function is still useful if you just don't unpack in the for loop
Excellent introduction! ❤
Line 269 of pdb.rst after commit 7db9d37... in issue 103694 says:
"The*convenience variables* are cleared when the program resumes execution so it's less likely to interfere with your program compared to using normal variables"
Looks like this is the reason it wasnt defined after you resumed :)
I am new to this channel
When I first saw thumbnail
I was like, why is attorney tom talking about python
Thanks for great changelog!
Really enjoyed the video. Pretty excited by @override and typed kwargs. And pre-commit now in cpython, wow this is win! It's fun that pdb became php xD
Cool video, thanks!
Finally, more months lol
10:37, just me or was that you keying in your password on camera?
But why the f string change? Makes no sense to me
Hey Anthony. Can you explain how to add a custom function to python builtins.
Thanks 🎉
Why the square brackets for the generic type variables where everyone else is using less than and greater than brackets for that…?
some other languages do that too -- plus there's already presence in python for squackets
At this point the Python std will just be a wrapper around C.
don't forget to link the video about generics :P
Both the type alias and the generic typing syntax looks just like Rust.
19:45 I'm not impressed that the new type aliases don't work with "isinstance".
Small typo in chapters:
- 9:18 "distutels"
- 29:47 "Pi upgrade"
I haven't added chapters -- those are generated
@@anthonywritescode uh, found it curious I couldn't find the timestamps in the description. I didn't know UA-cam autogenerates chapters.
I think pygame no longer works in 3.12 because of the distutils deprecation.
You exposed your sudo password at 10:37
it's "bad password"
override is all nice until the linter reports missing `override` on bare class methods like `__repr__` 💀
Did you just enter your root password on camera?
it's "bad password" -- I intentionally use a bad password here because of this
@@anthonywritescodemine is 8 asterisks
WOW Python became JS ._.
I HATE MARCH!
frob
What's the practical use for these type vars ..? Is this how core devs are fighting AI? by making language unreadable? Deeply saddened.
"promosm" ✋
This typing has got to stop
These hipsters introduce new typing shit, that doesn't even work with builtins like isinstance. It's ridiculous. As if bunch of javascript devs flooded core and started making decisions.
I think it is for optimization considerations and consistency, the original type hints are always cannot be used at runtime.
Лучший
Thanks 🎉