What IS typing.Annotated?

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 18

  • @luiss.l7904
    @luiss.l7904 10 годин тому +6

    Its rare to find "to the point" typing shown in python, its a pleasure to see such content.

  • @endersteph
    @endersteph 9 годин тому +8

    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 :)

    • @Carberra
      @Carberra  9 годин тому +3

      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!

    • @Proprogrammer001
      @Proprogrammer001 3 години тому +1

      Why is pydantic not enough? is it performance?

  • @imadetheuniverse4fun
    @imadetheuniverse4fun 8 годин тому +5

    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.

    • @Carberra
      @Carberra  7 годин тому +2

      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.

  • @eboyd53
    @eboyd53 9 годин тому +4

    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.

    • @Carberra
      @Carberra  9 годин тому +1

      Oh yikes, so it does. Thanks for pointing that out!

  • @sarimbinwaseem
    @sarimbinwaseem 10 годин тому

    Definitely gonna try this, makes my work easier...

  • @endersteph
    @endersteph 9 годин тому +1

    Shouldn't you add in the if statements, in case the field/metadata is falsy?

    • @Carberra
      @Carberra  8 годин тому +2

      Mm, yeah probably actually. Most use-cases probably wouldn't be affected by it, but thanks for pointing it out nonetheless!

  • @jagansai007
    @jagansai007 18 хвилин тому

    Nice theme.. I what's that?

  • @kzczd
    @kzczd 5 годин тому

    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.

    • @Carberra
      @Carberra  5 годин тому

      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.

  • @anferron
    @anferron 7 годин тому

    Looks more a MacOS than Windows. Maybe a virtual MacOS machine in your PC ?

    • @Carberra
      @Carberra  7 годин тому

      It's KDE Plasma themed to look (somewhat) like MacOS. I honestly love the dock + menubar way of doing things.

  • @maksimon519
    @maksimon519 7 годин тому

    i dont see a point to do this instead of explicitly put it into parameter `metadata` of `field()`

    • @Carberra
      @Carberra  7 годин тому

      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.