alternative title: Nerd gets excited he doesn't have to type ", None" as often
@anthonywritescode4 ай бұрын
it's true!
@samuelgunter4 ай бұрын
@@anthonywritescode isn't it True?
@abrahammurciano4 ай бұрын
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
@anthonywritescode4 ай бұрын
I have one! I forgot to link it in the description but it's there now!
@abrahammurciano4 ай бұрын
This is exactly why I've always annotated my generators as Iterator[T]. Finally I can use Generator!
@rosmelylawliet3 ай бұрын
Indeed, but I remember a bug with MyPy for that, and if I'm not mistaken, Anthony was its author :P
@ayhanfuat4 ай бұрын
It was so fun to watch you get happy about this. 😀
@tyrisnolam3 ай бұрын
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?
@anthonywritescode3 ай бұрын
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
@victordvickie4 ай бұрын
I never seen a grown man more happy than this, good addition btw lol
@bswck4 ай бұрын
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`.
@slavapasedko31394 ай бұрын
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.)
@anthonywritescode4 ай бұрын
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: kzbin.info/www/bejne/mKiYcnuaj6Zqm5Y - don't lru_cache a method: kzbin.info/www/bejne/qYfNpaNsqayiZsk - fixing a 9GB memory leak in cargo: kzbin.info/www/bejne/q6mtmXSOmaefmMU
@lukajeliciclux30744 ай бұрын
YESSSS!!!!! Generator[int,None,None] is just WHY?!
@d17-d7e4 ай бұрын
\o/ ... That's cool!
@flamendless4 ай бұрын
696.... It is nice
@bennyyouknow4 ай бұрын
Love your energy in this one 😊 Indeed a nice QoL improvement 🎉
@bacon4life4 ай бұрын
Cool, I have dozens of Generator[T, None, None] in my projects.
@jakubtybinski92464 ай бұрын
Pog
@dmytroparfeniuk26704 ай бұрын
Oh, nice)
@bashirabdelwahed404 ай бұрын
oh finally!!!!!!
@hansdietrich14964 ай бұрын
Yeah, that always caused eye cancer.
@danielmajer16484 ай бұрын
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
@AceofSpades57574 ай бұрын
That's fantastic. It's ugly and most people don't understand the other 2 anyhow
@sillybuttons9254 ай бұрын
wow that is great. Always found that annoying.
@s-h-f4 ай бұрын
Didn't understand much as I am still a beginner. But seems like they get rid of ugly (unnecessary) annotations. Thanks for demo.
@bswck4 ай бұрын
annotations are beautiful, not ugly.
@kRySt4LGaMeR4 ай бұрын
really cool, but it highlights how foreign type hints are to the core language
@senseikoudai61864 ай бұрын
Maybe an obvious question, but why were there two None values in the first place?
@slavapasedko31394 ай бұрын
Generator can yield, return and accept value using .send() Hence three typings for each of those possibilities
@anthonywritescode4 ай бұрын
I cover this in the video linked in the description in more detail as well!
@guscardvs4 ай бұрын
This could be true for Coroutine also
@anthonywritescode4 ай бұрын
indeed! though I'm not sure Coroutine got the same treatment :(
@Quarky_4 ай бұрын
Is there a difference between importing Generator from collections.abc and typing?
@iamcurrentlypooping4 ай бұрын
typing.Generator is a deprecated alias to collections.abc.Generator
@Quarky_4 ай бұрын
@@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