A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-July/120898.html below:

[Python-Dev] cpython: Issue 14814: Correctly return NotImplemented from ipaddress._BaseNetwork.__eq__

[Python-Dev] cpython: Issue 14814: Correctly return NotImplemented from ipaddress._BaseNetwork.__eq__ [Python-Dev] cpython: Issue 14814: Correctly return NotImplemented from ipaddress._BaseNetwork.__eq__Antoine Pitrou solipsis at pitrou.net
Sat Jul 7 15:55:35 CEST 2012
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.network_address == other.network_address and
> -                int(self.netmask) == int(other.netmask))
> +        try:
> +            return (self._version == other._version and
> +                    self.network_address == other.network_address 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.


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4