This project is archived and is in readonly mode.

#205 ✓invalid
Psycopg website

Inet class does not work for equality check

Reported by Psycopg website | April 4th, 2014 @ 03:35 PM

Submitted by:

The Inet class does not implement __eq__, and the standard "object" class seems to always return False.


import psycopg2, psycopg2.extras
  -> '2.5.2 (dt dec mx pq3 ext)'
psycopg2.extras.Inet('') == psycopg2.extras.Inet('')
   -> False
>>> psycopg2.extras.Inet('') in [psycopg2.extras.Inet(''), psycopg2.extras.Inet('')]
  -> False
>>> psycopg2.extras.Inet('').addr == psycopg2.extras.Inet('').addr


psycopg2.extras.Inet.__eq__ = lambda self, other: isinstance(other, psycopg2.extras.Inet) and self.addr == other.addr or False

psycopg2.extras.Inet.__ne__ = lambda self, other: not self.__eq__(other)
>>> psycopg2.extras.Inet('') == psycopg2.extras.Inet('') -> True >>> psycopg2.extras.Inet('') in [psycopg2.extras.Inet(''), psycopg2.extras.Inet('')] -> True

I'd rather see the __eq__ being implemented, versus checking .addr equality.
FWIW, the NumericRange (ala Range) defines an __eq__ operator.

Comments and changes to this ticket

  • Daniele Varrazzo

    Daniele Varrazzo April 4th, 2014 @ 04:19 PM

    • State changed from “new” to “open”

    I'm expecting we should fix the comparison operators as well, for the same reason we did it recently for Range, see ticket #193

    Can you provide a patch?

  • Daniele Varrazzo

    Daniele Varrazzo April 4th, 2014 @ 06:39 PM

    Thinking again about that, I don't like the Inet object, I don't think it provides anything additional compared to just a string. So I'm tempted to avoid adding extra features and maintaining it, except for serious bugs.

    Can you provide a reason to use Inet instead of a string?

  • Daniele Varrazzo

    Daniele Varrazzo May 5th, 2014 @ 11:05 PM

    • State changed from “open” to “invalid”

    Closing as I have no interest in adding feature to a class that has no reason to exist.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="">the new tracker</a>.
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.

Shared Ticket Bins