Created by: jwodder
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