Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/julian/compares
Simply define __eq__ and __repr__ in terms of a set of relevant fields
https://github.com/julian/compares
Last synced: 4 days ago
JSON representation
Simply define __eq__ and __repr__ in terms of a set of relevant fields
- Host: GitHub
- URL: https://github.com/julian/compares
- Owner: Julian
- License: mit
- Created: 2014-07-13T16:50:51.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-13T16:56:11.000Z (over 10 years ago)
- Last Synced: 2024-10-18T10:07:31.648Z (26 days ago)
- Language: Python
- Size: 125 KB
- Stars: 0
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: COPYING
Awesome Lists containing this project
README
========
Compares
========``Compares`` is a module that defines a single decorator, ``compares.via``\ ,
which removes some boilerplate around defining ``__eq__``\ , ``__ne__`` and
``__repr__`` for object comparisons and display.It takes advantage of the fact that there is often a set of relevant attributes
(fields) which should be used to compare instances.It is inspired by `twisted.python.util.FancyEqMixin
`_\ .Usage
-----.. code-block:: python
>>> import compares
>>> @compares.via(("foo", "bar"))
... class Foo(object):
... def __init__(self, foo, bar, baz):
... self.foo = foo
... self.bar = bar
... self.baz = baz>>> foo = Foo(foo=12, bar=13, baz=14)
>>> assert foo == Foo(foo=12, bar=13, baz="YEP")
>>> assert not foo == Foo(foo="NOPE", bar=13, baz="")
>>> assert repr(foo) == ""