On Sat,  7 Jul 2012 15:08:42 +0200 (CEST)
nick.coghlan <python-check...@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.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to