![anthonywritescode](/img/default-banner.jpg)
- Видео 1 098
- Просмотров 3 220 153
anthonywritescode
Добавлен 17 мар 2017
Various videos about programming and related topics. Most videos will feature open source software and programming best practices. For now, most videos will deal with python.
All slides and associated code are on github: github.com/anthonywritescode
All slides and associated code are on github: github.com/anthonywritescode
`x: float = False` is a valid annotation??? (intermediate) anthony explains #575
today we talk a bit about the numeric tower in mypy's type system and a few quirks that result from it.
- NotImplemented vs NotImplementedError: ruclips.net/video/GSBqmYUnBdk/видео.html
- NotImplemented is a bool?: ruclips.net/video/5XBs_fM3Nac/видео.html
playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY
==========
twitch: twitch.tv/anthonywritescode
dicsord: discord.gg/xDKGPaW
twitter: codewithanthony
github: github.com/asottile
stream github: github.com/anthonywritescode
I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!
- NotImplemented vs NotImplementedError: ruclips.net/video/GSBqmYUnBdk/видео.html
- NotImplemented is a bool?: ruclips.net/video/5XBs_fM3Nac/видео.html
playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY
==========
twitch: twitch.tv/anthonywritescode
dicsord: discord.gg/xDKGPaW
twitter: codewithanthony
github: github.com/asottile
stream github: github.com/anthonywritescode
I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!
Просмотров: 1 944
Видео
typing the untype-able with mypy plugins (advanced) anthony explains #574
Просмотров 6 тыс.14 дней назад
today I show an approach to make mypy understand a very dynamic pattern with a plugin! playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: codewithanthony github: github.com/asottile stream github: github.com/anthonywritescode I won't ask for subscriptions / likes / comments in videos but it really helps...
typing decorators sucks! here's an easier way (intermediate) anthony explains #573
Просмотров 9 тыс.Месяц назад
ParamSpec / TypeVar / Callable oh my! this skips all of that and gives a simple easy-to-reuse decorator (and more!) - how @ contextmanager works: ruclips.net/video/nr_q2y0qxFg/видео.html - contextmanagers the easy way: ruclips.net/video/ucGpcA9r4hU/видео.html playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: twitt...
adding test == others fail??? (intermediate) anthony explains #572
Просмотров 4 тыс.Месяц назад
today I show off a very strange bug in `black`'s testsuite and then how I found the problem which led to the fix! - what is test pollution? ruclips.net/video/FRteianaPMo/видео.html - fixing a flaky test with detect-test-pollution: ruclips.net/video/w5O4zTusyJ0/видео.html - debugging a sentry test pollution: ruclips.net/video/YEIeKdBmuUY/видео.html playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqu...
training a custom object detection model from scratch (yolov8) (intermediate) anthony explains #571
Просмотров 2,8 тыс.2 месяца назад
today I walk through my adventures training a custom object detection model (for identifying pokemon)! playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: codewithanthony github: github.com/asottile stream github: github.com/anthonywritescode I won't ask for subscriptions / likes / comments in videos but...
am I vulnerable to black's CVE? (2024-21503) (intermediate) anthony explains #570
Просмотров 6 тыс.3 месяца назад
today we walk through an analysis of black's recent CVE regarding regular expressions and whitespace! It's marked "Medium" with "Network" attack vector and we'll show whether it matters or not! - what is reDOS: ruclips.net/video/ECbls57_3jE/видео.html playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: c...
using git bisect to find a bug in nodejs (intermediate) anthony explains #569
Просмотров 4,5 тыс.3 месяца назад
today I walk through how I figured out a zip corruption problem and when it was introduced in nodejs! - how to use git bisect: ruclips.net/video/C2C7FTI8nB4/видео.html playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: codewithanthony github: github.com/asottile stream github: github.com/anthonywritesco...
using the 3ds touch screen without touch!?
Просмотров 1,9 тыс.4 месяца назад
today I show how I automated the 3ds including the touch screen! - my original 3ds automation project: ruclips.net/video/LvqmdC5YjXw/видео.html playlist: ruclips.net/p/PLWBKAf81pmOYZoIyNPAnR7i56KV1JaRr0 twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: codewithanthony github: github.com/asottile stream github: github.com/anthonywritescode I won't ask for subsc...
my thoughts on ruff
Просмотров 11 тыс.4 месяца назад
short and (bitter)sweet. playlist: ruclips.net/p/PLWBKAf81pmOZEPeIV2_pIESK5hRMAo1hR twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: codewithanthony github: github.com/asottile stream github: github.com/anthonywritescode I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like...
py-spy saved our python 3.11 rollout (intermediate) anthony explains #568
Просмотров 9 тыс.5 месяцев назад
today I show how I solved a perplexing performance degradation using a sampling profiler: py-spy! playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: codewithanthony github: github.com/asottile stream github: github.com/anthonywritescode I won't ask for subscriptions / likes / comments in videos but it r...
using memray to debug (and fix) a memory leak in krb5! (advanced) anthony explains #567
Просмотров 5 тыс.5 месяцев назад
today I show how I utilized memray to both find, debug, and ultimately fix a memory leak in krb5 sadly this was not the leak I was looking for though! playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: codewithanthony github: github.com/asottile stream github: github.com/anthonywritescode I won't ask fo...
ONE TERABYTE of RAM saved with a single line of code (advanced) anthony explains #566
Просмотров 54 тыс.5 месяцев назад
today I show off a small change I made at work with huge impact and explain how it works! - fork vs spawn ruclips.net/video/hzBtsDPJ1dM/видео.html - python sucks at copy-on-write ruclips.net/video/sdmcCQ7Em04/видео.html playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: codewithanthony github: github.co...
git: inline diffs with --word-diff! (intermediate) anthony explains #565
Просмотров 3,2 тыс.6 месяцев назад
today I show a tiny tip when working with patches in `git` (such as with `git diff` or `git log -p`) to show inline differences instead of full line differences playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: codewithanthony github: github.com/asottile stream github: github.com/anthonywritescode I wo...
I modded a gameboy advance (and a wii!) to get the rarest shiny pokemon! (jirachi?)
Просмотров 1,5 тыс.6 месяцев назад
today I show off how I soldered wires to a GBA and a wii and then coordinated them in software to reset for a shiny jirachi! - code: github.com/asottile/nintendo-microcontrollers - more about the method I used: ruclips.net/video/4rhHSKE1mwo/видео.html playlist: ruclips.net/p/PLWBKAf81pmOYZoIyNPAnR7i56KV1JaRr0 twitch: twitch.tv/anthonywritescode dicsord: discord.gg/xDKGPaW twitter: c...
prefer tuples to lists! (intermediate) anthony explains #564
Просмотров 9 тыс.6 месяцев назад
today I talk about the three reasons why I prefer tuples over lists! - tuples and their syntax quirks: ruclips.net/video/J3-tL6OnFWA/видео.html - tuples don't actually use parens! ruclips.net/video/EDGJ2TMuppM/видео.html - python is compiled? ruclips.net/video/FPJdre3mbD4/видео.html playlist: ruclips.net/p/PLWBKAf81pmOaP9naRiNAqug6EBnkPakvY twitch: twitch.tv/anthonywritescode dicsord: discord.g...
I imported my pokemon collection to sqlite using cv!
Просмотров 2,5 тыс.7 месяцев назад
I imported my pokemon collection to sqlite using cv!
pesky reDOS and python 3.11 (intermediate) anthony explains #563
Просмотров 3,6 тыс.7 месяцев назад
pesky reDOS and python 3.11 (intermediate) anthony explains #563
new 3.12 f-strings syntax! (intermediate) anthony explains #562
Просмотров 6 тыс.7 месяцев назад
new 3.12 f-strings syntax! (intermediate) anthony explains #562
NEW generic / alias syntax for python 3.12 (PEP 695) (intermediate) anthony explains #561
Просмотров 10 тыс.7 месяцев назад
NEW generic / alias syntax for python 3.12 (PEP 695) (intermediate) anthony explains #561
what is a BOM (byte-order-marker) (intermediate) anthony explains #560
Просмотров 3,5 тыс.8 месяцев назад
what is a BOM (byte-order-marker) (intermediate) anthony explains #560
I don't use backslashes (with one exception) (beginner - intermediate) anthony explains #559
Просмотров 6 тыс.8 месяцев назад
I don't use backslashes (with one exception) (beginner - intermediate) anthony explains #559
git: --first-parent (intermediate) anthony explains #558
Просмотров 3,1 тыс.8 месяцев назад
git: first-parent (intermediate) anthony explains #558
don't delete from pypi! (yank instead) (intermediate) anthony explains #557
Просмотров 3,4 тыс.8 месяцев назад
don't delete from pypi! (yank instead) (intermediate) anthony explains #557
the system design interview (intermediate - advanced) anthony explains #556
Просмотров 9 тыс.8 месяцев назад
the system design interview (intermediate - advanced) anthony explains #556
docker: connecting to localhost outside the container (intermediate) anthony explains #555
Просмотров 31 тыс.9 месяцев назад
docker: connecting to localhost outside the container (intermediate) anthony explains #555
stopping xargs early (intermediate) anthony explains #554
Просмотров 3,9 тыс.9 месяцев назад
stopping xargs early (intermediate) anthony explains #554
debugging a sentry test pollution! (intermediate) anthony explains #553
Просмотров 4,1 тыс.9 месяцев назад
debugging a sentry test pollution! (intermediate) anthony explains #553
automating the nintendo 3ds (hardware mod)
Просмотров 2,2 тыс.9 месяцев назад
automating the nintendo 3ds (hardware mod)
what is `Symbol` in js (intermediate) anthony explains #552
Просмотров 4,3 тыс.10 месяцев назад
what is `Symbol` in js (intermediate) anthony explains #552
tuple syntax doesn't have parens (beginner - intermediate) anthony explains #551
Просмотров 7 тыс.10 месяцев назад
tuple syntax doesn't have parens (beginner - intermediate) anthony explains #551
if not 0.0: print("python is a scripting languagle")
Thank you! This was very helpful for me.
Why is this guy using nano wtf?
it's better than that :) check the header (nano is an alias because I haven't fixed my habits)
I don't know how he does it but Anthony always manages to leave me speachless. Here I am thinking that I know Python quite well yet he always finds something to demo that makes me go O_o
We must simply respond "fair enough"
That's annoying. Is there a way to circumvent that somehow? I guess you could have tests that catch that but testing types in tests is not my favorite thing...
you could maybe do something with NewType though I haven't found a reason that this detail breaks me yet to rationalize the complexity of NewType
NotImplementedType can be found in the types module (!= typing), along with other useful types (NoneType, EllipsisType, etc) :)
Very nice video! False being a float I kinda expected but I honestly didn't know that the NotImplemented class existed.
there's more about NotImplemented linked in the description too if you're further curious
@@anthonywritescode I am sure I will get to it, I am currently at ~200th video of this playlist. It is very fun and informative to watch. :)
What I wonder is, why have these quirks in the typing system instead of expecting __lt__ to raise NotImplementedError instead?
to support other class instances as a right part of comparison/arithmetic operation that you don't know how to work with but they may know how ```python >>> 1 + MyNumberClass() ``` without `int` returning `NotImplemented` for `__add__` it won't be possible to use an overload in `MyNumberClass.__radd__` since `NotImplementedError` will be raised (and they can be raised by anything down the road while every function directly controls what it `return`s)
I explained the reason for that at the end! (note that in addition to the reasons I state in the video it's not raising also, it's returning -- exceptions aren't part of the type system)
So much of watching this for me is "That's weird... no, actually, that makes sense unfortunately"
So there is no python built in way to handle that?
Would the WikiDictionary be suitable for "registering" instances in a class variable for faster lookup later?
thanks man I lov u
I am very much enjoying your videos. Keep up the good work Anthony!
I know it's an old video, but I just came across this situation where C() > D() And C doesn't know about D but D did know about C, Is there a way to type hinted it in a way that mypy will know it is valid C() < D() but not C() < SomeOtherClass()?
not really, due to the way python is there aren't good mechanisms statically to know when things are comparable (besides well known ones like None which get special cased in the type system)
Love this, thanks Anthony!
there are various approaches for creating sentinels. the one with enum, but also `MISSING = type("_MISSING", (), {})()` or creating a custom class with the class keyword and then reusing a single instance of it is what I tend to use if I don't want `object()`. or even importing MISSING from dataclasses could work, but well. I'm not sure it's a good idea. everything depends whether you need concrete unions or a killer type "object" in a variable (or, more often, a parameter).
the enum approach is the only one I know that works well with mypy and narrowing
Very very interesting topic. I’m using this to implement a plugin for factoryboy type annotations (types-factoryboy). It’d be great to have more videos like this explaining how to write mypy plugins, as there is very little “digested” information available, only “just read what others did” kind of documentation.
how disgusting...
I'd love to hear your opinion on PDM. It's PEP standards friendly and it's dependency resolver is much more robust.
a few other comments have asked below vvv
Nice video, I am for giving people their choices. As a developer, I want a dependency manager that is opinionated and does not stray too far from selected apis. For me pip freeze bundles dependencies of dependencies, ignores missing/broken dependencies. Chances I no longer want to use that library as it is not well maintained or old. For projects like ansible-lint to deliberately break poetry support 100% of the time is childish.
? if poetry is that fragile and the official packaging tool can handle it surely poetry is the problem
Great as always
I've been using pyright in most cases over mypy which offers what I think is a simpler solution by 'tricking` the `__new__` return type. ```python from typing import TypeVar, Generic, Callable, TYPE_CHECKING, ParamSpec, reveal_type, Any P = ParamSpec("P") T = TypeVar("T", bound=Any) class Lazy(Generic[P, T]): if TYPE_CHECKING: _f: Callable[P, T] _inst: T | None def __new__(cls, obj: type[T]) -> T: ... def __init__(self, f: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> None: self._f = f self._inst = None self._args = args self._kwargs = kwargs def __getattr__(self, attr: str) -> T: if self._inst is None: self._inst = self._f(*self._args, **self._kwargs) return getattr(self._inst, attr) class Expensive: def foo(self) -> int: return 42 def main(): lazy = Lazy(Expensive) reveal_type(lazy.foo()) # type of "lazy.foo()" is "int"Pylance if __name__ == "__main__": main() ``` This still fails with mypy in a 2 areas and fails to properly reveal the type however passes with pyright. ``` mypy t.py t.py:12: error: "__new__" must return a class instance (got "T") [misc] t.py:34: error: "Expensive" not callable [operator] t.py:34: note: Revealed type is "Any" pyright t.py /home/leaver/nzthermo/t.py /home/leaver/nzthermo/t.py:34:17 - information: Type of "lazy.foo()" is "int" 0 errors, 0 warnings, 1 information ```
this doesn't preserve the attributes of the lazy class which is important for tests. if I wanted that I would just make a function return T and type ignore the return value but it is important to preserve the lazy attributes
I didn't know that mypy plugins was a thing
s = s.split(";", 1)[0] s = s.split("==", 1)[0] achieves the same, no?
yes and no, partition can help with logic after splitting without additional complexity. also it's a hair faster since the algorithm doesn't need to deal with arbitrary n
Fair!
argparse throws an error if pass in an empty string python hello.py "" hello.py: error: the following arguments are required: person
are you on windows? that should work fine I think (an empty string is a valid command line parameter)
@anthonywritescode Yes, I'm on windows. Ended up just using " ", so on to the next video.
RUclips algorithm likez me 😂
For the singleton field `Lazy._inst`, my first idea would've just been to store `None` and type as `Optional[R]`. Is there a benefit to using the specific `empty` object with the _EmptyType enum instead? Related timestamp: 1:14 for creating empty object, 14:10 for updating with enum type
None, Ellipsis, etc. would have worked for most cases, though Django's implementation uses an explicit empty singleton
If, for some reason, your expensive function returns None, you wouldn't be able to store it if you also used is as the singleton field. You would check against None and the function would run always because it would refer to both the actual lazily computed object as the singleton. Using an empty object and the `is` operator takes care of this, because `is` compares by reference/address. This address is guaranteed to be the one of the singleton
I'd be curious to hear your thoughts on how you expect/hope the type system evolves to _hopefully_ support concepts like proxy objects without the need for a plugin. Type annotations are definitely a big improvement when interacting with an existing codebase, but it still feels like a different language. The model I think of is TypeScript where there's reasonable support for type-level computations. But JS exposes far fewer implementation details, so it seems simpler to implement a type system that captures common forms of "dynamism" in JS. TS definitely has significant deficiencies (e.g. bivariant method arguments) but it seems like there may still be a lot of ideas that python could draw to be able to fully annotate a larger variety of constructs.
python has significantly more magic than js ever would have to deal with (descriptors, meta classes, etc.) such that I don't think the type system will (or even should!) represent every thing you can do. the only reason that I did make the proxy "work" is because it already existed. if the code were written with safety in mind such a pattern would not have been used
@@anthonywritescode that makes sense. Type annotations do seem to encourage a safer subset of the language. Thanks for the reply!
Thanks for that comment and adding that context. Good to know these tools are there, but better to design it, such that this is not needed 😂
It's so funny that a Typing video is full of typos: P
wouldn't like it any other way
he is back!
i only want to open an .exe file that is saved as sqlite why is it so hard ? i still cant figure it out
Don't have a clue what I just watched. My phone downloads this torrent all by itself every night which consists of a jpg, an SQLite and an XML. I delete it and the next time I go to sleep I wake up to find the same 15K file. Anyone know what could be going on?
Can you make a video about pyproject.toml?
I will not, no
the reality is Guido didn't really understand threading when he started python, that's normal for 99.9% of engineers. Until you spend a few years writing highly threaded applications, it's just hard to understand.
Hi Anthony Amazing feature, Thanks for sharing with us. One small help is needed. my mouse curosr is disappearing from my GIT command windows, could you please help me what setting command should I add into config file. Thanks
Whats a wat
Anthony, you just jumped right to the answer i was looking for, it's an instant subscribe ;)))
You wrote pre-commit?? 😮
One big reason I don't use tuples: typing variable-length tuples is annoying. list[T] is much easier than tuple[T, ...]. I guess the solution would be Sequence[T] anyway?
Thank you for the video! I was, however, waiting with bated breath for you to show an example of an error when the RHS had more than one value.
I assume you didn't watch to the end where I did exactly this yeah?
@@anthonywritescode Rewatched from beginning to end ... I saw where you talked about how an error would be generated, but I didn't see that actually demonstrated ... (?)
Your videos are gold. Thanks!
glad to help!
when i try to run make, it tells me "grep: /usr/share/arduino/hardware/arduino/avr/boards.txt: No such file or directory" How do i fix this?
you're missing the package that provides that -- I think it's in the readme
@@anthonywritescode i dont see anything in the readme. Am i missing something?
there should be an apt install command somewhere
I ran the apt install multiple times, to make sure it didn't miss something the first time, still nothing.
weird, it's supposed to pull in this transitive dep: arduino-core-avr
multiprocessing
Thank you for this! Usefull!
Thank you so much <3
Thanks for sharing this information, have you ever tried zenoh communication between host and docker containers? Like zenoh pub sub ?
Hi Antony, after one year of your video, still thinking you will not use poetry?
have the reasons in the video changed?
does "never" not include 2024?
Thanks - that was very helpful - I'll code it up shortly.
Interestingly, I can't seem to replicate this on macOS. I still get a connection refused running these exact same commands. I wonder if local firewall rules are disrupting the connection? Hmm