python 3.12 release highlights (beginner - advanced) anthony explains

Поділитися
Вставка
  • Опубліковано 19 жов 2024

КОМЕНТАРІ • 106

  • @rednafi
    @rednafi Рік тому +49

    Thanks for not trimming it down for the stupid youtube algorithm.

  • @DavidDellsperger
    @DavidDellsperger Рік тому +26

    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

    • @amir.hessam
      @amir.hessam Місяць тому

      @DavidDellsperger glad to see familiar faces here ...

  • @SebaSalinas91
    @SebaSalinas91 Рік тому +40

    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!

    • @con-f-use
      @con-f-use Рік тому +1

      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.

  • @pylang3803
    @pylang3803 Рік тому +11

    def x[T, U, V](y: U, z: V) -> list[T]: pass
    *holds head*

  • @RedShipsofSpainAgain
    @RedShipsofSpainAgain Рік тому +4

    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)

  • @henryschreiner
    @henryschreiner Рік тому +22

    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. :)

    • @acidnynex
      @acidnynex Рік тому +1

      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.

    • @Squeemos
      @Squeemos Рік тому

      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!

  • @Gaivs
    @Gaivs 11 місяців тому +1

    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.

  • @StepanKabachkov
    @StepanKabachkov Рік тому +23

    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 :)

    • @theendlessriver13
      @theendlessriver13 Рік тому +2

      Yeah - that also hit me as looking just "wrong" - but I'll get used to it I guess...

    • @ac130kz
      @ac130kz Рік тому

      nah, just a few touches

    • @peculiar-coding-endeavours
      @peculiar-coding-endeavours Рік тому +5

      Basically generics syntax is now closer to what it is in many other languages. What a shocker

    • @noobling8313
      @noobling8313 Рік тому

      Just don’t use the syntax unless it’s fun.

  • @amir.hessam
    @amir.hessam Рік тому +8

    I love the fact that Anthony mostly wings his videos! Very cool ♥

  • @aaronater1088
    @aaronater1088 Рік тому +1

    Appreciate the dissect on what's comin. Neat find on the NUL byte too

  • @RuslanKovtun
    @RuslanKovtun Рік тому +1

    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.

  • @d3stinYwOw
    @d3stinYwOw Рік тому +3

    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' :)

  • @Squeemos
    @Squeemos Рік тому +2

    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!

  • @_Ani_
    @_Ani_ Рік тому +1

    Thanks for the overview Anthony, a fun and insightful video as always!

  • @swapnilchavan7076
    @swapnilchavan7076 Рік тому +5

    Amazing content. I love to watch your videos. You are so informative. Thanks for doing this. I appreciate your efforts. 🙏

  • @hardikojha220
    @hardikojha220 Рік тому +1

    Unpacking of the TypedDict is a blessing

  • @DorkOrc
    @DorkOrc Рік тому

    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

  • @piyushgupta7210
    @piyushgupta7210 Рік тому

    that's just amazing.. thanks for taking out time and giving an overview of cool features of 3.12

  • @mrc1500
    @mrc1500 Рік тому +2

    Quite like the Generic types overhaul. I gave a wry chuckle and wondered when Python would become Scala 😏

  • @soberhippie
    @soberhippie Рік тому +3

    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)`?

    • @anthonywritescode
      @anthonywritescode  Рік тому +4

      no. type hints aren't part of the runtime like that they're mostly just comments

  • @lucasfcnunes
    @lucasfcnunes Рік тому +2

    In ISO 8601 monday is the start of the week + Week with weekday notation e.g. 2023‐W32‐1 is a monday

    • @alexandrugheorghe5610
      @alexandrugheorghe5610 Рік тому

      Thank goodness for that. No offense, but I can't stand the week starting on a Sunday!

  • @traal
    @traal Рік тому +3

    I like the override decorator. Explicit is better than implicit, right? 😊

  • @TankorSmash
    @TankorSmash Рік тому

    Informative and engaging, thanks for uploading. I love the nice error messages.

  • @Phaust94
    @Phaust94 Рік тому +3

    Thanks for the video! Love it! Love your style!
    The features not so much tho

  • @yorailevi6747
    @yorailevi6747 Рік тому +5

    Can someone add timestamps? A tldr and a way to jump into detail is really helpful

  • @18Maxim18
    @18Maxim18 11 місяців тому

    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)

  • @catcatcatcatcatcatcatcatcatca

    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.

  • @princeroshan4105
    @princeroshan4105 Рік тому +4

    I added those enums in calendar 😁, that was I guess my first PR to Cpython.

    • @niazhimselfangels
      @niazhimselfangels Рік тому +1

      Thanks, man! 😃

    • @pratyushrath1457
      @pratyushrath1457 Рік тому +1

      Great work! Keep contributing.

    • @RedShipsofSpainAgain
      @RedShipsofSpainAgain Рік тому

      Good job! Kinda of amazing that Python has had this bug for 23 years. How did no one think to fix this sooner??

    • @princeroshan4105
      @princeroshan4105 Рік тому +2

      @@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.

    • @RedShipsofSpainAgain
      @RedShipsofSpainAgain Рік тому

      @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?

  • @sadhlife
    @sadhlife Рік тому +4

    Instead of /dev/stdin you can just not give tokenize any file argument and it'll default to stdin

  • @piotrbogdanski8785
    @piotrbogdanski8785 Рік тому

    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

    • @anthonywritescode
      @anthonywritescode  Рік тому +2

      most people don't care -- subinterpreters is mostly for embedding python

  • @j.i.-cruz
    @j.i.-cruz Рік тому +1

    hyped for the vid! chapters would be super helpful

  • @jrheard
    @jrheard Рік тому +1

    ❤ for casual inheritance diss ❤❤

  • @user-kn4wt
    @user-kn4wt Рік тому

    really enjoyed this! thanks for all your videos 🙏🙏

  • @mrswats
    @mrswats Рік тому

    Always love these, so I know what to tell my colleagues about the new python version!

  • @bernardcrnkovic3769
    @bernardcrnkovic3769 Рік тому +1

    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.

    • @catcatcatcatcatcatcatcatcatca
      @catcatcatcatcatcatcatcatcatca Рік тому +1

      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.

  • @windowviews150
    @windowviews150 9 місяців тому

    Cool kb. What is it? freestyle pro?

  • @DrSnej
    @DrSnej Рік тому

    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.

  • @daineminton9687
    @daineminton9687 Рік тому +1

    ...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.

  • @debakarr
    @debakarr Рік тому +5

    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.

  • @dangerousdansg
    @dangerousdansg Рік тому

    Great video, I learnt so much!

  • @rosmelylawliet
    @rosmelylawliet Рік тому +1

    I love pyupgrade, i use it regularly

  • @MakeDataUseful
    @MakeDataUseful Рік тому

    Generics is a little scary looking!

  • @maxvangent4171
    @maxvangent4171 Рік тому +1

    With the new f-string parsing we can finally write php in python 🙃

  • @onlymen22
    @onlymen22 Рік тому

    Thanks dude what a great content ❤❤❤

  • @skarfie123
    @skarfie123 Рік тому

    The batched function is still useful if you just don't unpack in the for loop

  • @Md.AlmasAli
    @Md.AlmasAli Рік тому

    Excellent introduction! ❤

  • @Soulthym
    @Soulthym Рік тому

    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 :)

  • @asrk3855
    @asrk3855 Рік тому

    I am new to this channel
    When I first saw thumbnail
    I was like, why is attorney tom talking about python

  • @atugushev
    @atugushev Рік тому

    Thanks for great changelog!

    • @atugushev
      @atugushev Рік тому

      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

  • @IvanHabunek
    @IvanHabunek Рік тому

    Cool video, thanks!

  • @djazz0
    @djazz0 Рік тому +1

    Finally, more months lol

  • @simdimdim
    @simdimdim Рік тому

    10:37, just me or was that you keying in your password on camera?

  • @putnam120
    @putnam120 Рік тому +1

    But why the f string change? Makes no sense to me

  • @rudranagkatroju9970
    @rudranagkatroju9970 Рік тому

    Hey Anthony. Can you explain how to add a custom function to python builtins.

  • @destinyinworld4064
    @destinyinworld4064 Рік тому +1

    Thanks 🎉

  • @desertfish74
    @desertfish74 Рік тому

    Why the square brackets for the generic type variables where everyone else is using less than and greater than brackets for that…?

    • @anthonywritescode
      @anthonywritescode  Рік тому

      some other languages do that too -- plus there's already presence in python for squackets

  • @funkdefied1
    @funkdefied1 Рік тому

    At this point the Python std will just be a wrapper around C.

  • @qexat
    @qexat Рік тому

    don't forget to link the video about generics :P

  • @funkdefied1
    @funkdefied1 Рік тому

    Both the type alias and the generic typing syntax looks just like Rust.

  • @cparks1000000
    @cparks1000000 Рік тому

    19:45 I'm not impressed that the new type aliases don't work with "isinstance".

  • @avasam06
    @avasam06 10 місяців тому

    Small typo in chapters:
    - 9:18 "distutels"
    - 29:47 "Pi upgrade"

    • @anthonywritescode
      @anthonywritescode  10 місяців тому +1

      I haven't added chapters -- those are generated

    • @avasam06
      @avasam06 10 місяців тому

      @@anthonywritescode uh, found it curious I couldn't find the timestamps in the description. I didn't know UA-cam autogenerates chapters.

  • @MyriadColorsCM
    @MyriadColorsCM Рік тому

    I think pygame no longer works in 3.12 because of the distutils deprecation.

  • @w2lkm2n
    @w2lkm2n Рік тому

    You exposed your sudo password at 10:37

  • @qexat
    @qexat Рік тому

    override is all nice until the linter reports missing `override` on bare class methods like `__repr__` 💀

  • @computerfre3
    @computerfre3 Рік тому +3

    Did you just enter your root password on camera?

    • @anthonywritescode
      @anthonywritescode  Рік тому +7

      it's "bad password" -- I intentionally use a bad password here because of this

    • @desertfish74
      @desertfish74 Рік тому

      @@anthonywritescodemine is 8 asterisks

  • @commandcracker42
    @commandcracker42 Рік тому

    WOW Python became JS ._.

  • @kosmonautofficial296
    @kosmonautofficial296 Рік тому +1

    I HATE MARCH!

  • @qexat
    @qexat Рік тому

    frob

  • @yomajo
    @yomajo Рік тому +1

    What's the practical use for these type vars ..? Is this how core devs are fighting AI? by making language unreadable? Deeply saddened.

  • @raymondpearson1971
    @raymondpearson1971 Рік тому

    "promosm" ✋

  • @DrDeuteron
    @DrDeuteron Рік тому

    This typing has got to stop

  • @yomajo
    @yomajo Рік тому

    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.

    • @吳政霖-b9t
      @吳政霖-b9t Рік тому

      I think it is for optimization considerations and consistency, the original type hints are always cannot be used at runtime.

  • @proofit404
    @proofit404 Рік тому

    Лучший

  • @shmuelk3018
    @shmuelk3018 Рік тому

    Thanks 🎉