Btw, there is a library called beartype which is amazing and lets you conveniently and efficiently define validators, and in general lets you easily enforce strict typing at practically 0 execution time-cost :)
Oh wow, that's definitely worth a look-in! I remember seeing a library that enforced strict typing before and was trying to look for it earlier but couldn't find it. I'll give that one a shot!
so in the first example, it's just a way to "document" the validation next to the type, right? because the exact same thing could be achieved by just having the validation function be a standalone function and calling it in setattrs, or just having the logic hardcoded into setattrs directly.
The second argument actually does get run, but it would also serve as a form of documentation, yeah. It's one of many ways it can be done, but is the way that is becoming more and more common that are built for the purpose of validation like Pydantic and Msgspec.
I dont know if you're aware that youtube is auto-translating your videos titles, and it is making unninformative output, i would recommend to turn of title autotranslating because as a native spanish speaker, the youtube translator is underperformant.
Is it? Thanks for the heads up, I'll see about turning that off. They're doing all sorts of stuff with translation and AI at the moment, doesn't surprise me it's not working very well considering it's Google.
Is that what that argument's for? I guess now you say it it's pretty obvious, I hadn't put the two together haha. Either way, I just used a dataclass here to reduce boilerplate for the example.
Its rare to find "to the point" typing shown in python, its a pleasure to see such content.
Btw, there is a library called beartype which is amazing and lets you conveniently and efficiently define validators, and in general lets you easily enforce strict typing at practically 0 execution time-cost :)
Oh wow, that's definitely worth a look-in! I remember seeing a library that enforced strict typing before and was trying to look for it earlier but couldn't find it. I'll give that one a shot!
Why is pydantic not enough? is it performance?
so in the first example, it's just a way to "document" the validation next to the type, right? because the exact same thing could be achieved by just having the validation function be a standalone function and calling it in setattrs, or just having the logic hardcoded into setattrs directly.
The second argument actually does get run, but it would also serve as a form of documentation, yeah. It's one of many ways it can be done, but is the way that is becoming more and more common that are built for the purpose of validation like Pydantic and Msgspec.
This example excludes anyone who has yet to have a 1st birthday so be careful if your use case needs to include infants less than 1 year old.
Oh yikes, so it does. Thanks for pointing that out!
Definitely gonna try this, makes my work easier...
Shouldn't you add in the if statements, in case the field/metadata is falsy?
Mm, yeah probably actually. Most use-cases probably wouldn't be affected by it, but thanks for pointing it out nonetheless!
Nice theme.. I what's that?
I dont know if you're aware that youtube is auto-translating your videos titles, and it is making unninformative output, i would recommend to turn of title autotranslating because as a native spanish speaker, the youtube translator is underperformant.
Is it? Thanks for the heads up, I'll see about turning that off. They're doing all sorts of stuff with translation and AI at the moment, doesn't surprise me it's not working very well considering it's Google.
Looks more a MacOS than Windows. Maybe a virtual MacOS machine in your PC ?
It's KDE Plasma themed to look (somewhat) like MacOS. I honestly love the dock + menubar way of doing things.
i dont see a point to do this instead of explicitly put it into parameter `metadata` of `field()`
Is that what that argument's for? I guess now you say it it's pretty obvious, I hadn't put the two together haha. Either way, I just used a dataclass here to reduce boilerplate for the example.