5 Cool Dataclass Features In Python

Поделиться
HTML-код
  • Опубликовано: 24 сен 2024

Комментарии • 32

  • @throstlewanion
    @throstlewanion 2 дня назад +11

    I think it's important to mention that @property is perfectly usable in other kinds of classes. This is not a feature unique to dataclasses. Otherwise nice video

  • @MatthewMakesAU
    @MatthewMakesAU 2 дня назад +9

    You had it almost right! Perimeter is pronounced the same as parameter, but "ih" instead of "ah" for the second a

    • @STIUTK
      @STIUTK 2 дня назад +1

      As an extra point it's common (at least where I'm from) to put the emphasis on the second syllable, which sounds almost like the word rim - so peRIMeter instead of PErimeter

  • @michaelcummings7246
    @michaelcummings7246 2 дня назад +3

    When I read about dataclasses in the docs I didn't really see the point to using them but after watching this video I can see how they are more useful than I thought. I would like to see another video on some of the more advanced features for sure.

    • @SHAMIKII
      @SHAMIKII 2 дня назад

      Echo the same thought

  • @chriskeo392
    @chriskeo392 2 дня назад +3

    Next... advanced dataclasses video please

  • @Marc-ElianBegin
    @Marc-ElianBegin День назад

    Nice. Perhaps a video on cool pydantic features would be a good complement.

  • @visantibanez
    @visantibanez День назад

    Thank you for sharing your Python knowledge. You make learning it easy and interesting :)

  • @pacersgo
    @pacersgo 13 часов назад

    __post_init__ is useful, list attributes should be initialized by a list factory because it is mutable

  • @islamicdesiretv
    @islamicdesiretv 2 дня назад +1

    these are very cool features as your worst features video was beneficial for me
    I was stuck at some point in one project implicit str concatenation was making my project difficult but your video was beneficial for me

  • @AMMullan
    @AMMullan 2 дня назад

    Really well described :) might have been useful to discuss slots and also show more on how the default_factory etc work (and the caveats of having attributes that aren't set initially where they don't show in the repr) - maybe those for a follow up vid? :)

  • @riccardozappitelli450
    @riccardozappitelli450 2 дня назад

    0:43 that was personal

  • @farzadmf
    @farzadmf 2 дня назад

    Question: if we do `friends: list[str] = []`, is the list gonna be shared by all instances?

  • @cerealport2726
    @cerealport2726 2 дня назад

    Bob is not just more than James, Bob is more than all of us.

  • @ashrafyousif1240
    @ashrafyousif1240 2 дня назад

    Would make more videos about data classes please

  • @AnRodz
    @AnRodz День назад

    possible to you make `friends` a list[Person]?

  • @ladislavhusty9466
    @ladislavhusty9466 2 дня назад

    What is the difference between pydantic BaseModel and dataclasses?

    • @footflaps
      @footflaps 2 дня назад

      Pydantic is far superior eg built in data validation, supports deep structures, validation, serialisation, etc. If you use already use Pydantic, not much point, dataclasses are a step backwards.

  • @danialmunsif
    @danialmunsif 2 дня назад

    super knowledge

  • @co48756
    @co48756 2 дня назад

    I don't understand what the @property accomplishes? Could you not just create the same method but without the decorator?

    • @michaelcummings7246
      @michaelcummings7246 2 дня назад

      Using @property is considered more pythonic way of doing it.

    • @olivergrim7634
      @olivergrim7634 2 дня назад

      it should be more of an attribute than a method

    • @tiongah7690
      @tiongah7690 2 дня назад

      from the video it is implied that the with @property we don't have to explicitly call the method when the attribute changes right?

    • @Michallote
      @Michallote 2 дня назад

      It is an attribute that is computed from other attributed. There are many things that need to be recomputed once an attribute changes. Property makes it so that it is always computed properly

    • @吳政霖-b9t
      @吳政霖-b9t 2 дня назад

      1. The usage method cannot prevent users from misuse and overwriting it, such as ary.len = 10.
      2. Using property, you can customize its setter (@.setter) and deleter (@.deleter), so you can accept more flexible syntax while retaining the setter method to check the input, such as: circle.c, circle.r = (0, 0), 10
      3. The method cannot be used in special cases where the expression cannot be used, such as: match circle: case Circle(r=0): print(f'This is a dot.')

  • @williamsquires3070
    @williamsquires3070 2 дня назад

    Okay, but what if you want the address of an object created by the @dataclass decorator?

  • @michaelhoffmann2891
    @michaelhoffmann2891 День назад

    Minor note: I'm pretty sure I read in PEP that __init__ shouldn't have a return type. I too had started to put -> None there, until I read the "don't bother".
    More pertinent: one thing I'd really like to see, as someone who works with REST APIs day in, day out, is better "native" support for JSON. Serialisation, schema-to-dataclass, etc. There's various support packages that do this more or less well, but as so often they're bolted on and of varying level of support.

    • @DrDeuteron
      @DrDeuteron День назад

      Type hinting dunder init is so very unpythonic….on both ends. Y’all might get guido out of retirement.

  • @loukassideris
    @loukassideris 2 дня назад

    Is Luigi a friend of yours? You use him almost everywhere. And where is his brother, Mario?

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 2 дня назад

    Thank you 😊