[Python-Dev] Advice on numbers.py implementation of binary mixins.
Nick Coghlan
ncoghlan at gmail.com
Sat Jun 14 03:23:19 CEST 2008
Raymond Hettinger wrote:
> The question for the group is what to put on the XXX line.
>
> 1. Limit it to type(self). This approach claims the least knowledge
> about other types and uses their __rand__ methods().
>
> 2. Use type(self), int, and long. This approach says that we know that
> ints and longs can be reasonably converted to an int; however, it means
> that any int/long subtype cannot use __rand__ to override the mixin's
> __and__.
>
> 3. Emulate the PEP as closely as possible and accomodate subclassing
> without changing behaviors. This approach is a bit complex:
>
> knowntypes = (set(type(self).__mro__)
> & set(type(other.__mro__))
> - set(type(Integral.__mro__))
> | set([int, long]))
> if isinstance(other, tuple(knowntypes)):
4. As 2, but skip int/long subclasses:
if type(other) in (int, long) or isinstance(other, type(self)):
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list