New Features You Need To Know In Python 3.12

preview_player
Показать описание
Python 3.12 is just around the corner, and I couldn't be more excited! 🎉🐍 In this video, I'll not only dive into the thrilling new features and improvements coming our way in Python 3.12 but also discuss some elements that will be removed in the upcoming release.

🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

Social channels:

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Dale Hagglund

🔖 Chapters:
0:00 Intro
0:51 Better error messages
2:06 Performance improvements
2:28 Comprehension inlining
3:26 Smaller object sizes
3:41 Immortal objects
4:39 Per-interpreter GIL (PEP684)
5:47 F-strings
6:36 TypedDict kwargs
7:32 Override decorator
8:26 Generic types
10:24 Other
11:37 Outro

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

We make use of kwargs in our library for passing user arguments to functions from other libraries (i.e in our wrapper functions)

JohnWalz
Автор

I have two use cases for kwargs:
1. when creating a wrapper function for another function.
2. when passing around parameters for ML and data science projects. Typically I store these as json files, so it’s nice to use dictionaries to pass around those parameters.

navidshokouhi
Автор

Hey @ArjanCodes, if you want function annotations, then create a Protocol class and define the __call__ method and then add the type anotations for the parameters in that __call__ method. When you will use the the Protocol to type a function it will describe it with the type of the __call__ method.

ihordrahushchak
Автор

Kwargs are a really great feature when you are writing larger repositories. When passing arguments to other repeatedly called functions, this makes the code much cleaner. One example if with spark dataframes. I have one function that does all of the filtering with arguments per column. Most other functions call this function at the beginning with kwargs being passed directly to it.

landwolf
Автор

I have not used kwargs too much myself, but I have seen some really good use cases. One of them is collecting a bunch of optional (kw) arguments at top level, and then reducing the kwargs dict as you move down the tree of functions or methods, as each of them have explicit named arguments set by some of the kwargs provided by their "parent" function (the caller) and then collecting the remainder as a smaller kwargs dict passed to their children.

sinkingboat
Автор

I usually use *args and **kwargs when creating custom decorators. I like to create decorators for code reusability and custom tools for my projects. Also a custom paters is the composition and some time you can create some custom wrappers utilities that receive an object instance with some arbitrary parameters and you perform some kind of logic.

josealejandroconcepcion
Автор

Thanks for again for your excellent content. I would love to see a comprehensive tutorial for typing. All of existing ones go through the basics, but someone needs to explain how I can get VSCode and Black to pass on real code with a "strict" setting.

markchadwick
Автор

I would love to see more content in the form of series on
1. threading vs multiprocessing
2. distributed computing in python using ray framework or its equivalent

mayureshkedari
Автор

Using kwargs with argparse for passing command line args to the program entry point is one of my favorite Python patterns. Nothing more satisfying than writing main(**vars(args)) instead of passing everything to main manually.

MegaJolaus
Автор

Nested quotes in f-strings is a useful feature when refactoring, and I think a good choice to allow (there was significant debate on this one). However, it also looks bad and is harder to quickly parse visually, thus I hope code formatters will reformat it when possible. This would make for a nice compromise, because if I refactor my code to place a string inside of an f-strings, I could get the ease of readability of alternating quote types with a simple call to my formatter.

jevandezande
Автор

🎯 Key Takeaways for quick navigation:

00:56 🐍 Python 3.12 introduces improved error messages, including suggestions for missing imports and common coding errors, enhancing the coding experience.
02:24 🚀 Python 3.12 brings performance improvements, particularly in comprehension inlining, resulting in up to 2x speedup in some cases and an overall 11% performance boost.
03:51 🧊 Python 3.12 introduces "immortal objects, " objects with a fixed reference count, reducing memory usage and simplifying code optimization.
04:49 🌐 Python 3.12 lays the foundation for per-interpreter Global Interpreter Lock (GIL), enhancing multi-core utilization in future versions.
05:48 📜 F-strings in Python 3.12 become less restrictive, allowing nested double quotes for improved string formatting.
06:44 🎯 Python 3.12 simplifies type annotations, allowing for easier definition of keyword argument types and introduces the "override" keyword for explicit method overriding.
08:40 🧬 Python 3.12 introduces a new syntax for type parameters and generic classes/functions, simplifying the handling of generics.
10:32 📂 Pathlib now includes a "walk" method, making it easier to traverse directory trees, and CPython 3.12 supports instrumentation for monitoring calls, returns, lines, and exceptions, improving debugging and coverage tools.
11:28 ❌ Python 3.12 removes deprecated modules like asyncore and asynchat, encourages the use of async.io, and deprecates old method names in the unit test package.

Made with HARPA AI

onhazrat
Автор

Yes i use kwargs when I have a wrapper function over a core function and I still want to provide all the functionality of the core function without having to update the params in two places.

sugo
Автор

override decorator is a nice addition. Before every method was virtual. Now you have a bit more control over it.

bersi
Автор

the TypedDict kwargs feature will be useful for cases where we have function params that are being passed around or through as a group

CountChocula
Автор

Using kwargs in Django view helpers. Have a few pdf reports that require generation and using pdfkit underneath. So kwargs is being used to pass context for pdf report generation and then also for configuring pdfkit

jjcbvg
Автор

I have a query builder that passes user arguments (optional and required) along to a DB client as a formatted query string. Good for when I have to maintain a lot of different etl and dbt pipelines and want to use the same basic development pattern for them. In general kwarg unpacking is really invaluable or any kind of client wrapper function or class.

swannie
Автор

The place that i use kwargs is when passing arguments to celery tasks in flask applications

drweb
Автор

The enablement of having nested quotes in f-string is great when you need to access some dictionary field inside the f-string.

MartinVotruba
Автор

5:48 (f-strings), very much needed and appreciated!

Andrumen
Автор

The override decorator is my favorite new feature.

MrAlanCristhian