Skip to content

Commit 1fc2c69

Browse files
committed
docs: update artisanal example
Ref #1472
1 parent 50334f3 commit 1fc2c69

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

docs/why.md

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -250,39 +250,19 @@ is roughly
250250
... else:
251251
... return not result
252252
...
253-
... def __lt__(self, other):
254-
... if other.__class__ is self.__class__:
255-
... return (self.a, self.b) < (other.a, other.b)
256-
... else:
257-
... return NotImplemented
258-
...
259-
... def __le__(self, other):
260-
... if other.__class__ is self.__class__:
261-
... return (self.a, self.b) <= (other.a, other.b)
262-
... else:
263-
... return NotImplemented
264-
...
265-
... def __gt__(self, other):
266-
... if other.__class__ is self.__class__:
267-
... return (self.a, self.b) > (other.a, other.b)
268-
... else:
269-
... return NotImplemented
270-
...
271-
... def __ge__(self, other):
272-
... if other.__class__ is self.__class__:
273-
... return (self.a, self.b) >= (other.a, other.b)
274-
... else:
275-
... return NotImplemented
276-
...
277253
... def __hash__(self):
278254
... return hash((self.__class__, self.a, self.b))
279255
>>> ArtisanalClass(a=1, b=2)
280256
ArtisanalClass(a=1, b=2)
281257
```
282258

283259
That's quite a mouthful and it doesn't even use any of *attrs*'s more advanced features like validators or default values.
284-
Also: no tests whatsoever.
260+
If you pass `order=True`, there's even four more methods: `__lt__`, `__le__`, `__gt__`, and `__ge__`.
285261
And who will guarantee you, that you don't accidentally flip the `<` in your tenth implementation of `__gt__`?
262+
*attrs* will also do the right thing around [hashing](hashing):
263+
It will write a `__hash__` for you if your class should be hashable and marks your class as unhashable if not.
264+
265+
Also: no tests whatsoever.
286266

287267
It also should be noted that *attrs* is not an all-or-nothing solution.
288268
You can freely choose which features you want and disable those that you want more control over:
@@ -300,7 +280,7 @@ You can freely choose which features you want and disable those that you want mo
300280
```
301281

302282
:::{admonition} Summary
303-
If you don't care and like typing, we're not gonna stop you.
283+
If you don't care and like the sound of your mechanical keyboard, we're not gonna stop you.
304284

305285
However it takes a lot of bias and determined rationalization to claim that *attrs* raises the mental burden on a project given how difficult it is to find the important bits in a hand-written class and how annoying it is to ensure you've copy-pasted your code correctly over all your classes.
306286

0 commit comments

Comments
 (0)