Тёмный
No video :(

Raymond Hettinger - Dataclasses: The code generator to end all code generators - PyCon 2018 

PyCon 2018
Подписаться 21 тыс.
Просмотров 124 тыс.
50% 1

Speaker: Raymond Hettinger
The PEP 557 dataclasses module is available in starting in Python 3.7. It will become an essential part of every Python programmer's toolkit. This talk shows what problem the module solves, explains its key design decisions, and provides practical examples of how to put it to work.
Dataclasses are shown to be the next step in a progression of data aggregation tools: tuple, dict, simple class, bunch recipe, named tuples, records, attrs, and then dataclasses. Each builds upon the one that came before, adding expressiveness at the expense of complexity.
Dataclasses are unique in that they let you selectively turn-on or turn-off its various capabilities and it lets the user choose the underlying data store (either instance dictionary, instance slots, or an inherited base class).
Dataclasses and typing.NamedTuple both use variable annotations which were new in Python 3.6.
Slides can be found at: speakerdeck.com/pycon2018 and github.com/PyCon/2018-slides

Опубликовано:

 

12 май 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 47   
@drd105
@drd105 6 лет назад
Hettinger is becoming a better and better speaker with experience.
@medthehatta
@medthehatta 5 лет назад
I dunno, I feel that he spoke less clearly here than usual, and the webpage slides are kinda lazy, especially considering he has done live demos in the past.
@DeprecatedAPI
@DeprecatedAPI 5 лет назад
These videos are gold
@TimSavage-drummer
@TimSavage-drummer 5 лет назад
13:15 Yes! I developed a library for building, validating and serialise/deserialising data structures. There is always a stream of "small" requests or huge changes in behaviour.
@x86me75
@x86me75 6 лет назад
i really enjoyed it. Great talk.
@ekbastu
@ekbastu 5 лет назад
The man the legend
@timofeydanshin6904
@timofeydanshin6904 5 лет назад
Not a single time did he say "there must be a better way". It's like a Steve Jobs keynote without the 'one more thing'.
@SpellsOfTruth
@SpellsOfTruth 4 года назад
So dataclasses are Java Lombok Library @Data class annotation? Awesome, and super simple.
@Zergosss
@Zergosss 5 лет назад
Why can't we just use parameter: list instead of this factory thingy? I understand the purpose of factories for non-standard objects, but is it needed for an empty list?
@DeMurker
@DeMurker 5 лет назад
Yes, it is needed. If you would write def __init__(self, parameter=[]) then all instances of the class refer to the same list.
@japrogramer
@japrogramer 5 лет назад
Say i have a data class and instead of using setattr i want to have a function that sets the key ... How can i know which attr is a a data class field? And how can i define custom fields
@aoeu256
@aoeu256 5 лет назад
For the first one dataClsObj.__class__.__dataclass_fields__, for the second one try inheritance? @dataclass class newdataclass (olddataclass): pass If not try: from copy import deepcopy, Newdataclass = olddataclass.deepcopy() Newdataclass.hue : int = 5 Newdataclass = dataclass(Newdataclass)
@h82fail
@h82fail 5 лет назад
More questions would have been nice, they never give him enough time.
@ChrisBNisbet
@ChrisBNisbet 6 лет назад
__dataclass_fields__ for lightness and saturation seem wrong. Shouldn't they say .type = float rather than .name = float?
@Zergosss
@Zergosss 5 лет назад
It seems to be corrected in the slides that I downloaded from his Twitter.
@andreasweiden9056
@andreasweiden9056 6 лет назад
Both links to the slides are dead...
@Egzvorg
@Egzvorg 6 лет назад
you can find slides on twitter @raymondh
@alexanderreynolds7638
@alexanderreynolds7638 6 лет назад
This tweet specifically has the dropbox link to the slides for this talk: twitter.com/raymondh/status/995693882812915712
@Achrononmaster
@Achrononmaster 5 лет назад
Would be even cooler if the dataclass support in-place replace() functionality like :: replace(c, hue+=10) Just sayin.
@calebgindelberger3046
@calebgindelberger3046 5 лет назад
Wasn't there a joke about collections authors always getting feature requests in there somewhere?
@drygordspellweaver8761
@drygordspellweaver8761 2 года назад
Errr... c.hue += 10 Attributes are already mutable
@ArjoonnSharma
@ArjoonnSharma 6 лет назад
hello my name is "Erick Smith"? 0:33
@narnbrez
@narnbrez 4 года назад
eric schmidt
@fiordnord
@fiordnord 4 года назад
@@narnbrez and whats the punch in this line?
@yochem9294
@yochem9294 3 года назад
@@fiordnord erick wrote the dataclasses, he explains he nornally talks about thing he wrote for python. But not this time, raymond did not write the dataclasses module. So he introduces himself with the name of the author of the data classes
@chillydickie
@chillydickie 2 года назад
Raymond, i'll take the 10 bitcoins /day job...
@chair547
@chair547 4 года назад
python is so big
@j2kun
@j2kun 6 лет назад
Why not just dict() and tuple() instead of asdict() and astuple()
@gnikgnak
@gnikgnak 6 лет назад
When defining the methods, they exist in the local scope of the class definition. If you define a method called "dict" it will shadow the builtin dict inside that local scope. You'll find that Python experts are averse to naming things the same as builtins, even if it doesn't cause a problem in the current implementation. They have a healthy paranoia that future changes, made hastily, will cause a problem. The unofficial standard for conversion methods is to name them "as_type". You'll see that pattern in the standard library and many popular packages. When designing an API, it's best to follow the standard even if you have a better idea. Folks familiar with the standard don't want to learn new names for concepts they already know.
@j2kun
@j2kun 6 лет назад
I meant, why not just reuse the builtins? Do they behave any differently?
@gnikgnak
@gnikgnak 6 лет назад
Yes, they are different. I'm not really sure what you mean by "(re)use the builtins," but I'm taking a wild guess that you are suggesting using the dict or tuple constructors. The tuple constructor might work if the dataclass were iterable. There was a discussion about this idea ( github.com/ericvsmith/dataclasses/issues/21 ) which you might be interested in. The dict constructor would only work if the dataclass instance was itself a dict or an iterable of pairs, which in either case would prevent the tuple constructor from working.
@juanarrivillaga2683
@juanarrivillaga2683 3 года назад
@@gnikgnak No, this is absolutely not true at all. A method called `dict` will *never* shadow the built-in `dict`. First, the method *exists in the classes namespace*, which is not the local namespace.
@MikeSelik
@MikeSelik 3 года назад
@@juanarrivillaga2683 Check out the `locals()` output during class creation. Here's an example of shadowing the builtins: In [1]: class Foo: ...: dict = lambda: print("Gotcha!") ...: bar = dict() Gotcha!
@DeathDragon-uj4ed
@DeathDragon-uj4ed 4 года назад
Very low volume :(
@JohnDellOso-vl9tx
@JohnDellOso-vl9tx Год назад
The quality of the screens is absolutely terrible - no matter what the resolution.
@bradywb98
@bradywb98 4 года назад
> 0.033 seconds > "33 nanoseconds" how to speed up python with one simple trick :P
@psikoumaha
@psikoumaha 4 года назад
He divided the result by 1 million because timeit runs it 1 million times, so you get the value for one sample
@ThunderAppeal
@ThunderAppeal 3 года назад
Python is a god awful language, only slightly better than javascript. I will only mention java and php because some fool will come along and accuse me of being a lover of those awful langauges. Python does everything it can to disempower the programmer despite all evidence that suggests that it 'empowers programmers', rather than doing everything in a properly programmatic structured way python forces the programmer to do everything 'pythonically' which is painfully tedious. The saving social grace of python is that its participants arent rabid boy fans like in other languages, the females are a different matter, I would have actually expected better from the women considering how the feminist movement loves to insinuate how anything that is not imbued with estrogen it is bad.
@drygordspellweaver8761
@drygordspellweaver8761 2 года назад
Python is what finally helped me push through the barrier of learning a language and now my comprehension of other languages is so much stronger than before. You’re wrong about it depriving programmers of learning about “programmatic structure”. An engineering difficulty is an engineering difficulty regardless of the language. Most algorithms have been solved already. You don’t have to reinvent the wheel.
@ZeroPlayerGame
@ZeroPlayerGame 15 дней назад
Sorry, what's your rationale to come on a random video on Python-dedicated channel to voice your opinion on an unrelated video? Genuinely baffled.
Далее
Reuven M. Lerner - Practical decorators - PyCon 2019
29:12