see also "dataclasses" since python 3.7
Attrs – the Python library everyone needs (2016)
31–40 of 115 posts
Re: Attrs – the Python library everyone needs (2016)
#32see also "dataclasses" since python 3.7
Re: Attrs – the Python library everyone needs (2016)
#33Someone should tell this person about dataclasses
Re: Attrs – the Python library everyone needs (2016)
#34Earlier quoted context omitted.
Not a python guy, so confused as to why a thing called namedtuple behaves like dataclasses, what are their different usecases?
Named tuples have been around for a long time (since 2.6), whereas dataclasses are a relatively recent addition to the standard library (3.7). Their differences are highlighted in the dataclasses PEP: https://www.python.org/dev/peps/pep-0557/#why-not-just-use-n...
Re: Attrs – the Python library everyone needs (2016)
#35Earlier quoted context omitted.
Named tuples have been around for a long time (since 2.6), whereas dataclasses are a relatively recent addition to the standard library (3.7). Their differences are highlighted in the dataclasses PEP: https://www.python.org/dev/peps/pep-0557/#why-not-just-use-n...
looks like the key thing is immutability
There is no way, however, to make a named tuple mutable.
Re: Attrs – the Python library everyone needs (2016)
#36Someone should tell this person about dataclasses
[0] https://www.python.org/dev/peps/pep-0557/#why-not-just-use-a...
Re: Attrs – the Python library everyone needs (2016)
#37Someone should tell this person about dataclasses
If you take 10 seconds to read attrs website they do go over the differences and maybe discussing those would be more valuable than some cheap snark.
Re: Attrs – the Python library everyone needs (2016)
#38Earlier quoted context omitted.
We always used attrs with the runtime type validators anyway. Getting those types checked in Python was way more valuable to my teams than the minor boilerplate reduction. If you’re worried about the performance hit of extra crap happening at runtime… dear lord use another programming language. Dataclasses is just… meh. Pydantic and Attrs just have so many great features, I would never use dataclasses unless someone…
Thanks. You do make a lot of good points. Attrs just has the features I need for now. It certainly feel a touch verbose but I’m happy to pay the price.
Re: Attrs – the Python library everyone needs (2016)
#39Re: Attrs – the Python library everyone needs (2016)
#40Earlier quoted context omitted.
Came here to say this, dataclasses have been super helpful for a big part of the pain point highlighted by the author. More often than not, that is enough for me.
Yes. There needs to be a very good reason for me to pull in a third party library (in this day and age, given supply chain attacks, etc.). I don’t see what Attrs gives me that dataclasses does not.
Sticking with the "rusty, leaking batteries included!" in the STL is a bad call and I don't believe it is safe, either; most of the STL is abandonware that is just being shipped for backward compatibility sake. Don't make future product decisions, design decisions etc. based on Python teams' deprecation requirements!
I've been writing Python a long time and have grown quite frustrated by some of its warts. But every time I look at seriously investing in another language attrs is one of the few things I wouldn't want to give up. It's not perfect but I'll take very, very good when I can get it, yeah?