Getting to Know Python 3.7- Data Classes, Async-Await and More(blog.heroku.com)
blog.heroku.com
Getting to Know Python 3.7- Data Classes, Async-Await and More
https://blog.heroku.com/python37-dataclasses-async-await
3 comments
There's also pydantic, which provides validation using type hints: https://pydantic-docs.helpmanual.io
Also related to that I just came across a library that can generate json schema from a dataclass https://github.com/s-knibbs/dataclasses-jsonschema
There's also https://github.com/Fatal1ty/mashumaro for json serialization.
There's also https://github.com/Fatal1ty/mashumaro for json serialization.
worth mentioning the attr library in this context, which is I think the most popular implementation and inspiration for dataclasses (I think I read the reason it's not in core is to allow it to move faster). My interpretation of dataclasses in the stlib was to put a seal of approval on attr.
Look pretty good, but that approach won't be sufficient for more advance serialisation e.g. you want a user with password in case X and without in case Y. Type system is not expressive enough, so you need something more expressive like Marshmallow.
attrs is basically what dataclasses haven't dared to be: https://www.attrs.org
For more context see https://www.attrs.org/en/stable/why.html#data-classes and https://www.python.org/dev/peps/pep-0557/#why-not-just-use-a...
For more context see https://www.attrs.org/en/stable/why.html#data-classes and https://www.python.org/dev/peps/pep-0557/#why-not-just-use-a...
True that.
I'm not an OOP person, but to me, dataclasses seem like a solution in search of a problem. Or, even more nefariously, it seems akin to the Clojure model, if the core team didn't develop it, it won't be officially blessed.
I'm more than willing to hear the other side, but I've read some and watched a few talks on dataclasses, and while their implementation is neat, I cannot figure out how I'd used them on a regular basis.
I'm not an OOP person, but to me, dataclasses seem like a solution in search of a problem. Or, even more nefariously, it seems akin to the Clojure model, if the core team didn't develop it, it won't be officially blessed.
I'm more than willing to hear the other side, but I've read some and watched a few talks on dataclasses, and while their implementation is neat, I cannot figure out how I'd used them on a regular basis.
> I'm not an OOP person, but to me, dataclasses seem like a solution in search of a problem.
As an OOP person, I would say that dataclasses are an incomplete solution to a complex, multi-faceted problem, and a solution which doesn't really solve any of those facets. It is pretty much unusable as it is; for any practical use you need to extend it based on the specific needs of your application. But then it makes more sense to use a more complete solution such as attrs, which covers a much wider set of problems.
As an OOP person, I would say that dataclasses are an incomplete solution to a complex, multi-faceted problem, and a solution which doesn't really solve any of those facets. It is pretty much unusable as it is; for any practical use you need to extend it based on the specific needs of your application. But then it makes more sense to use a more complete solution such as attrs, which covers a much wider set of problems.
Nice! I always end up implementing some portion of this on every major project I do. After using something like Rust's Serde crate, you really miss this functionality in Python.
Nice article! I am just getting into writing my own decorators and I will appreciate every example and docs I can find. After 30+ years of preferring Lisp languages, I have been forced to accept Python as my main driver because of the ecosystem for deep learning, probabilistic programming, etc. Both of the books I am writing right now are Python books (one is general building intelligent systems with Python, the other covers knowledge graphs and deep learning and how they play together). Virtually all my work for the last 4 years has also used Python.
Anyway, it is rough emotionally using Lisp languages infrequently but improvements in Python 3.7 as described in this article make it less painfull.
Anyway, it is rough emotionally using Lisp languages infrequently but improvements in Python 3.7 as described in this article make it less painfull.
Any favorite non trivial paradigms in python for the functional enthusiast?
I probably write fewer class definitions than most developers, and write more functions. Avoid global data. Not functional, but I like to write small libraries.
Fun fact: contextvars are implemented as HAMTs, the same immutable maps as found in Clojure.
When 3.7 was first released, I created a library to use dataclasses and add some light type validation to them. The library grew and now also supports some basic serialization mapping.
I'd love some feedback/issues/PRs
https://github.com/abatilo/typed-json-dataclass