Тёмный

PEP 696 is a huge quality-of-life improvement (intermediate) anthony explains  

anthonywritescode
Подписаться 42 тыс.
Просмотров 8 тыс.
50% 1

Опубликовано:

 

24 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 38   
@DavidDellsperger
@DavidDellsperger 3 месяца назад
alternative title: Nerd gets excited he doesn't have to type ", None" as often
@anthonywritescode
@anthonywritescode 3 месяца назад
it's true!
@samuelgunter
@samuelgunter 3 месяца назад
@@anthonywritescode isn't it True?
@abrahammurciano
@abrahammurciano 3 месяца назад
Generator[T, None, None] is one of those things that everyone knows about but most don't know why. It would be cool to have a video explaining what the other types are for
@anthonywritescode
@anthonywritescode 3 месяца назад
I have one! I forgot to link it in the description but it's there now!
@abrahammurciano
@abrahammurciano 3 месяца назад
This is exactly why I've always annotated my generators as Iterator[T]. Finally I can use Generator!
@rosmelylawliet
@rosmelylawliet 2 месяца назад
Indeed, but I remember a bug with MyPy for that, and if I'm not mistaken, Anthony was its author :P
@ayhanfuat
@ayhanfuat 3 месяца назад
It was so fun to watch you get happy about this. 😀
@bswck
@bswck 3 месяца назад
So excited about that change. I often violated the rule of maximum specificity in the return type and simply used a higher-in-hierarchy `Iterator[T]`, which is obviously not an equivalent: it was only suitable for cases where I didn't have to access `.send()`, `.throw()` or `.close()`; but that was the majority of cases. Nevertheless, so cool I can just use `Generator[T]` now. There are lots of other use cases, for example `textual.App[T]` with the `T` defaulting to `None`.
@victordvickie
@victordvickie 3 месяца назад
I never seen a grown man more happy than this, good addition btw lol
@lukajeliciclux3074
@lukajeliciclux3074 3 месяца назад
YESSSS!!!!! Generator[int,None,None] is just WHY?!
@slavapasedko3139
@slavapasedko3139 3 месяца назад
Hi Anthony. Thank you for such great content. It’s really hard to find intermediate/advanced python topics on youtube because most of the content is created for beginners and there’s no point to watch it if you already have at least some production experience. Keep up the great work. I’d like to ask you to record a video about Python memory management, how to write cpu/ram efficient code, tips & tricks, what to avoid and all python memory-cpu-related stuff, memory leaks, profiling, etc. (I watched a video about preloading & gc.freeze() it was really fun and cool stuff you did.)
@anthonywritescode
@anthonywritescode 3 месяца назад
it's difficult to pinpoint a strategy specifically -- at least when writing pure python you don't really have much control over it other than not globally caching things forever (and not using buggy C libraries!) -- that said here's a few others I've done about memory (explains videos are collected at github.com/anthonywritescode/explains) - using memray to debug a memory leak in krb5: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-bw5AHdZA7e4.html - don't lru_cache a method: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-sVjtp6tGo0g.html - fixing a 9GB memory leak in cargo: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-uxJhAXdBlbc.html
@bacon4life
@bacon4life 3 месяца назад
Cool, I have dozens of Generator[T, None, None] in my projects.
@flamendless
@flamendless 3 месяца назад
696.... It is nice
@d17-d7e
@d17-d7e 3 месяца назад
\o/ ... That's cool!
@bennyyouknow
@bennyyouknow 3 месяца назад
Love your energy in this one 😊 Indeed a nice QoL improvement 🎉
@tyrisnolam
@tyrisnolam 2 месяца назад
Hello Anthony, thank you for the great videos, I learn a lot from you! Do you think you'll have time to explain async context managers?
@anthonywritescode
@anthonywritescode 2 месяца назад
maybe? probably not though -- tbh they're basically just context managers that let the event loop yield (if that makes any sense). I tend to stay way from python's async personally -- been really unimpressed with it and can't quite stomach the coloring problem it introduces. honestly multiprocessing / multithreading has been easier for me to write personally
@s-h-f
@s-h-f 3 месяца назад
Didn't understand much as I am still a beginner. But seems like they get rid of ugly (unnecessary) annotations. Thanks for demo.
@bswck
@bswck 3 месяца назад
annotations are beautiful, not ugly.
@hansdietrich1496
@hansdietrich1496 3 месяца назад
Yeah, that always caused eye cancer.
@danielmajer1648
@danielmajer1648 3 месяца назад
Everytime I write something else than python I wish it was python. Unfortunately mypy is still not standard for most of the folks like typescript
@AceofSpades5757
@AceofSpades5757 3 месяца назад
That's fantastic. It's ugly and most people don't understand the other 2 anyhow
@jakubtybinski9246
@jakubtybinski9246 3 месяца назад
Pog
@kRySt4LGaMeR
@kRySt4LGaMeR 3 месяца назад
really cool, but it highlights how foreign type hints are to the core language
@sillybuttons925
@sillybuttons925 3 месяца назад
wow that is great. Always found that annoying.
@bashirabdelwahed40
@bashirabdelwahed40 3 месяца назад
oh finally!!!!!!
@dmytroparfeniuk2670
@dmytroparfeniuk2670 3 месяца назад
Oh, nice)
@senseikoudai6186
@senseikoudai6186 3 месяца назад
Maybe an obvious question, but why were there two None values in the first place?
@slavapasedko3139
@slavapasedko3139 3 месяца назад
Generator can yield, return and accept value using .send() Hence three typings for each of those possibilities
@anthonywritescode
@anthonywritescode 3 месяца назад
I cover this in the video linked in the description in more detail as well!
@guscardvs
@guscardvs 3 месяца назад
This could be true for Coroutine also
@anthonywritescode
@anthonywritescode 3 месяца назад
indeed! though I'm not sure Coroutine got the same treatment :(
@Quarky_
@Quarky_ 3 месяца назад
Is there a difference between importing Generator from collections.abc and typing?
@iamcurrentlypooping
@iamcurrentlypooping 3 месяца назад
typing.Generator is a deprecated alias to collections.abc.Generator
@Quarky_
@Quarky_ 3 месяца назад
@@iamcurrentlypooping thanks! I was recently going through the docs, and I don't recall seeing any deprecation warning, that's why I was confused. Looks I just overlooked it :⁠-⁠P