]> git.ipfire.org Git - location/libloc.git/commitdiff
python: Fix rich comparison function for Country
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 21 Feb 2024 15:54:49 +0000 (15:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 21 Feb 2024 15:54:49 +0000 (15:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/country.c

index 5129b01a4aa2c1cde0dcfac632b7513402c4d56c..6d7ba111902ff60e96760edd2ee00bdcd6515dd6 100644 (file)
@@ -114,8 +114,16 @@ static int Country_set_continent_code(CountryObject* self, PyObject* value) {
        return 0;
 }
 
-static PyObject* Country_richcompare(CountryObject* self, CountryObject* other, int op) {
-       int r = loc_country_cmp(self->country, other->country);
+static PyObject* Country_richcompare(CountryObject* self, PyObject* other, int op) {
+       int r;
+
+       // Check for type
+       if (!PyObject_IsInstance(other, (PyObject *)&CountryType))
+               Py_RETURN_NOTIMPLEMENTED;
+
+       CountryObject* o = (CountryObject*)other;
+
+       r = loc_country_cmp(self->country, o->country);
 
        switch (op) {
                case Py_EQ: