[Python-Dev] cpython: Issue 14814: Correctly return NotImplemented from ipaddress._BaseNetwork.eq (original) (raw)
Antoine Pitrou solipsis at pitrou.net
Sat Jul 7 15:55:35 CEST 2012
- Previous message: [Python-Dev] Problem with hg hook for devguide repo?
- Next message: [Python-Dev] cpython: Issue 14814: Correctly return NotImplemented from ipaddress._BaseNetwork.__eq__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, 7 Jul 2012 15:08:42 +0200 (CEST) nick.coghlan <python-checkins at python.org> wrote:
def eq(self, other): - if not isinstance(other, BaseNetwork): - raise TypeError('%s and %s are not of the same type' % ( - self, other)) - return (self.version == other.version and - self.networkaddress == other.networkaddress and - int(self.netmask) == int(other.netmask)) + try: + return (self.version == other.version and + self.networkaddress == other.networkaddress and + int(self.netmask) == int(other.netmask)) + except AttributeError: + return NotImplemented
I think the isinstance() test was correct. If you have an object which duck-types IPNetwork, you probably want its eq to be called, not yours.
Regards
Antoine.
- Previous message: [Python-Dev] Problem with hg hook for devguide repo?
- Next message: [Python-Dev] cpython: Issue 14814: Correctly return NotImplemented from ipaddress._BaseNetwork.__eq__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]