Skip to content

Add attrs#875

Merged
vinta merged 1 commit intovinta:masterfrom
jwodder:attrs
Sep 15, 2017
Merged

Add attrs#875
vinta merged 1 commit intovinta:masterfrom
jwodder:attrs

Conversation

@jwodder
Copy link
Contributor

@jwodder jwodder commented Apr 15, 2017

What is this Python project?

attrs allows you to declare your class's instance attributes once, and it then takes care of generating the boilerplate __init__, __eq__, __repr__, etc. methods for you, turning this:

from functools import total_ordering
@total_ordering
class Point3D(object):
    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z

    def __repr__(self):
        return (self.__class__.__name__ +
                ("(x={}, y={}, z={})".format(self.x, self.y, self.z)))

    def __eq__(self, other):
        if not isinstance(other, self.__class__):
            return NotImplemented
        return (self.x, self.y, self.z) == (other.x, other.y, other.z)

    def __lt__(self, other):
        if not isinstance(other, self.__class__):
            return NotImplemented
        return (self.x, self.y, self.z) < (other.x, other.y, other.z)

into this:

import attr
@attr.s
class Point3D(object):
    x = attr.ib()
    y = attr.ib()
    z = attr.ib()

Example taken from this blog post extolling the virtues of attrs written by the author of Twisted.

What's the difference between this Python project and similar ones?

The only other project like this that I'm aware of is characteristic, which the author abandoned to create attrs instead.

--

Anyone who agrees with this pull request could vote for it by adding a 👍 to it, and usually, the maintainer will merge it when votes reach 20.

@pitcons
Copy link

pitcons commented Apr 24, 2017

👍

@ibewatuwant
Copy link

Awesoms

@butla
Copy link

butla commented Sep 14, 2017

This definitely needs to get up there.

@vinta vinta merged commit 4b9feb5 into vinta:master Sep 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants