Live data from Hacker News

I use Attrs instead of Pydantic

threeofwands.com

11–20 of 76 posts

Re: I use Attrs instead of Pydantic

#11

Recently there's a strong tendency in the Python ecosystem to wrap perfectly fine idioms with even higher abstractions. Not sure if I like this, in the end it leads to a lot of cargo culting and people writing code they don't fully understand because it contains a lot of metaclass and runtime magic. But I understand that a lot of developers find this attractive, and type annotations really provide a good channel for…

[deleted]

Re: I use Attrs instead of Pydantic

#12

Recently there's a strong tendency in the Python ecosystem to wrap perfectly fine idioms with even higher abstractions. Not sure if I like this, in the end it leads to a lot of cargo culting and people writing code they don't fully understand because it contains a lot of metaclass and runtime magic. But I understand that a lot of developers find this attractive, and type annotations really provide a good channel for…

I agree, Python is/was about simplicity. That is why for validation I use (Maat)[https://pypi.org/project/Maat/] It's just a dictionary to describe the data, and it's easy to expand.

Re: I use Attrs instead of Pydantic

#13

Recently there's a strong tendency in the Python ecosystem to wrap perfectly fine idioms with even higher abstractions. Not sure if I like this, in the end it leads to a lot of cargo culting and people writing code they don't fully understand because it contains a lot of metaclass and runtime magic. But I understand that a lot of developers find this attractive, and type annotations really provide a good channel for…

I agree, Python is/was about simplicity. That is why for validation I use (Maat)[ https://pypi.org/project/Maat/ ] It's just a dictionary to describe the data, and it's easy to expand.

I also prefer my python to stay simple.

Maat looks really interesting for this use-case.

Re: I use Attrs instead of Pydantic

#14

Recently there's a strong tendency in the Python ecosystem to wrap perfectly fine idioms with even higher abstractions. Not sure if I like this, in the end it leads to a lot of cargo culting and people writing code they don't fully understand because it contains a lot of metaclass and runtime magic. But I understand that a lot of developers find this attractive, and type annotations really provide a good channel for…

One aspect may be that people just aren't that satisfied with some of the design decisions of Python. In this case the (perceived) issue is probably unnecessary verbosity in declaring classes, which I agree with. Due to the lack of macros changes are made through decorators and other metaprogramming magic, which brings about some collateral issues.

I find it preferable that such changes are possible outside the central committee bureaucracy. You really don't want to end up like C++ w.r.t language evolution.

Re: I use Attrs instead of Pydantic

#15
I absolutely hate the attrs “joke” names attr.ib and attr.s.

That’s it. I simply can’t stand them, they drive me crazy. When I first saw them I wondered what the fuck “ib” meant. And the thing is, I’d expect every decent python programmer to have the same reaction: . is syntax; it simply can’t be part of a name. The library is called “attrs”, so why is it imported as “attr”? I simply don’t know what the author thought he was doing.

I just don’t see how it is appropriate for a serious library to contain a joke that’s going to trip up literally every programmer with any taste. Maybe this is my problem, maybe one day I’ll relax and wonder why I was making such a big deal about it. But for the last several years it has made me think that the author completely lacks the judgement required to be a library author.

To add to my criticisms, imagine what the python ecosystem would look like if everyone thought they could have names that spanned attribute lookup syntax!

Re: I use Attrs instead of Pydantic

#16

I absolutely hate the attrs “joke” names attr.ib and attr.s. That’s it. I simply can’t stand them, they drive me crazy. When I first saw them I wondered what the fuck “ib” meant. And the thing is, I’d expect every decent python programmer to have the same reaction: . is syntax; it simply can’t be part of a name. The library is called “attrs”, so why is it imported as “attr”? I simply don’t know what the author though…

The `attrs` authors address it in the documentation:

https://www.attrs.org/en/stable/overview.html#on-the-attr-s-...

At first, some people have a negative gut reaction to that; resembling the reactions to Python’s significant whitespace. And as with that, once one gets used to it, the readability and explicitness of that API prevails and delights.

For those who can’t swallow that API at all, attrs comes with serious business aliases: attr.attrs and attr.attrib.

Re: I use Attrs instead of Pydantic

#18
post #16

I absolutely hate the attrs “joke” names attr.ib and attr.s. That’s it. I simply can’t stand them, they drive me crazy. When I first saw them I wondered what the fuck “ib” meant. And the thing is, I’d expect every decent python programmer to have the same reaction: . is syntax; it simply can’t be part of a name. The library is called “attrs”, so why is it imported as “attr”? I simply don’t know what the author though…

The `attrs` authors address it in the documentation: https://www.attrs.org/en/stable/overview.html#on-the-attr-s-... At first, some people have a negative gut reaction to that; resembling the reactions to Python’s significant whitespace. And as with that, once one gets used to it, the readability and explicitness of that API prevails and delights. For those who can’t swallow that API at all, attrs comes with serious…

Yes, I know. That doesn’t redeem it. I want never to have to read those names in python code I'm working with; the documentation entry doesn't achieve that.

And anyway, the library is called “attrs”, so why is it imported as “attr”?

Re: I use Attrs instead of Pydantic

#19

Recently there's a strong tendency in the Python ecosystem to wrap perfectly fine idioms with even higher abstractions. Not sure if I like this, in the end it leads to a lot of cargo culting and people writing code they don't fully understand because it contains a lot of metaclass and runtime magic. But I understand that a lot of developers find this attractive, and type annotations really provide a good channel for…

Yes, this higher abstractions tendency is clearly away from "Flat is better than nested". Creating good abstractions is so difficult (and important) that it should not be done lightly by everyone.

The recent proliferation of type annotations is also trending towards the static typing mindset, which is also cargo culting on a massive scale.

Re: I use Attrs instead of Pydantic

#20
post #10

Specifically I use pydantic for validation, so yes, I expect pydantic to iterate over a list of 10000 elements and verify these are all ints.

Yeah, not doing that when using typescript is leading to so many bugs. Yes the compiler is happy, but you will get a runtime error as the json decoding converted it to a string, not the expected number type being passed around. So add in a second step that verifies that the decoded json actually matches the type and fail fast. One thing I liked about Elm was the decoders, a bit hassle to write but made it so easy catching bugs when backend and frontend people weren't on the same page.
Post reply on HN