Add Color.__eq__/__ne__ for value comparison, closes #307
Color had __hash__ but no __eq__/__ne__, violating the Python convention that hashable objects must support equality comparison. Two Color objects with identical RGBA values would not compare equal. Now supports comparison with Color objects, tuples, and lists: Color(255, 0, 0) == Color(255, 0, 0) # True Color(255, 0, 0) == (255, 0, 0) # True Color(255, 0, 0) != (0, 0, 0) # True Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
41d5007371
commit
95463bdc78
2 changed files with 66 additions and 8 deletions
|
|
@ -23,6 +23,7 @@ public:
|
|||
static sf::Color fromPy(PyColorObject*);
|
||||
static PyObject* repr(PyObject*);
|
||||
static Py_hash_t hash(PyObject*);
|
||||
static PyObject* richcompare(PyObject*, PyObject*, int);
|
||||
static int init(PyColorObject*, PyObject*, PyObject*);
|
||||
static PyObject* pynew(PyTypeObject* type, PyObject* args=NULL, PyObject* kwds=NULL);
|
||||
static PyObject* get_member(PyObject*, void*);
|
||||
|
|
@ -75,6 +76,7 @@ namespace mcrfpydef {
|
|||
" anim = mcrfpy.Animation('fill_color.r', 255, 0.5, 'linear')\n"
|
||||
" anim.start(frame)\n"
|
||||
),
|
||||
.tp_richcompare = PyColor::richcompare,
|
||||
.tp_methods = PyColor::methods,
|
||||
.tp_getset = PyColor::getsetters,
|
||||
.tp_init = (initproc)PyColor::init,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue