Comments (4)
I think the ideal here is:
def __eq__(self, that):
if not isinstance(that, type(self)):
return NotImplemented
return (
self.__slots__ == that.__slots__
and all(item == iota for item, iota in zip(self, that))
)
from blue.
oh hai,
imo, the ‘ideal’ is far from ideal.
- for starters, this code implicitly depends on the type being iterable.
- on top of that, it implicitly assumes that iteration yields the values worth comparing, which may or may not be the same as having equal values in each field defined in
__slots__
- the variable ‘that’ would contrast with a variable ‘this’, but this is python, which uses ‘self’. so ‘self’ / ‘other’ would be a better choice.
- a variable named ‘iota’ means nothing
- a variable ‘item’ compared to ‘iota’ doesn't mean much either
that said, here's a quick attempt that would be closer to ‘ideal’, and lo and behold, it doesn't suffer from perceived formatting ‘problems’ either:
class C:
def __eq__(self, other):
if not isinstance(other, type(self)):
return NotImplemented
if self.__slots__ != other.__slots__:
return False
for x in self.__slots__:
if getattr(self, x) != getattr(other, x):
return False
return True
the ‘ideal’ solution would be to not write any code at all, and use attrs
instead to declaratively define attributes and whether they should be included in an an equality comparison.
from blue.
This ticket is not a discussion of that __eq__
method, but of the formatting of specific lines by the black
tool.
from blue.
which is way more subtle and complex than this ticket seems to imply; see psf/black#2156 (comment)
from blue.
Related Issues (20)
- [docs request] Examples of pyproject.toml and setup.cfg
- [Question] Active? HOT 2
- 0x and 0b case
- Coverage requirement fails
- Exclude not workin pyproject.toml
- error: cannot format main.py: Cannot parse: 66:21 HOT 1
- blue is incompatible with flake8 v5 HOT 9
- Unable to run Blue formatting HOT 4
- Don't expand brackets
- How to properly use Blue in GitHub Actions? HOT 1
- https://iblueit.dev/ is broken due to missing resources HOT 1
- Don't bind specific versions of `black`, monkey patch methods on `ast` level
- Continuation lines defined by extra indentation HOT 1
- Comply with PEP-8 for indentation of parameters in function definition HOT 3
- leave function-scope imports alone
- [docs request] Adding example pre-commit config to README
- Is this repository still active? The last update was 9 month ago HOT 4
- Doc: how to use blue with vscode? HOT 1
- Vim Plugin for blue HOT 5
- blue changes `%autoreload 2` in jupyter ntoebooks to random hex
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blue.