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()
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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/vinta/awesome-python/pull/875
**Author:** [@jwodder](https://github.com/jwodder)
**Created:** 4/15/2017
**Status:** ✅ Merged
**Merged:** 9/15/2017
**Merged by:** [@vinta](https://github.com/vinta)
**Base:** `master` ← **Head:** `attrs`
---
### 📝 Commits (1)
- [`b1145c8`](https://github.com/vinta/awesome-python/commit/b1145c8eb15c82f984239c3835be08355886a4fa) attrs is awesome.
### 📊 Changes
**1 file changed** (+1 additions, -0 deletions)
<details>
<summary>View changed files</summary>
📝 `README.md` (+1 -0)
</details>
### 📄 Description
## 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`](https://glyph.twistedmatrix.com/2016/08/attrs.html) written by the author of [Twisted](https://twistedmatrix.com/trac/).
## What's the difference between this Python project and similar ones?
The only other project like this that I'm aware of is [`characteristic`](https://github.com/hynek/characteristic), which the author abandoned to create `attrs` instead.
--
Anyone who agrees with this pull request could vote for it by adding a :+1: to it, and usually, the maintainer will merge it when votes reach **20**.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/vinta/awesome-python/pull/875
Author: @jwodder
Created: 4/15/2017
Status: ✅ Merged
Merged: 9/15/2017
Merged by: @vinta
Base:
master← Head:attrs📝 Commits (1)
b1145c8attrs is awesome.📊 Changes
1 file changed (+1 additions, -0 deletions)
View changed files
📝
README.md(+1 -0)📄 Description
What is this Python project?
attrsallows 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:into this:
Example taken from this blog post extolling the virtues of
attrswritten 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 createattrsinstead.--
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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.