PEP0238: overriding // (__intdiv__) ??

Robin Becker robin at
Wed Jul 25 08:34:33 EDT 2001

In article <snatltotvlevdqc7kaj1m8v82o5fv51543 at>, Kirby Urner
<urner at> writes
>Maybe I missed it.  Did the PEP specify what we'd use
>to override the // operator in a class?  __intdiv__  and 
>__rintdiv__ ?  Seems we'd need something like this, to
>have our objects play along.  And I'd think this wrinkle 
>should become available simultaneously with //.  
If and when the grand type class unification takes place and ints,
longs, floats rationals and the like are all properly sub-classable,
will it possible to inject behaviours into those types? If so then I can
trivially change '/' by changing the base implementations for the
various types.

I suppose that there are efficiency arguments involved, but the compiler
must issue a divide instruction anyhow and leave it up to the operand
classes to decide what to do.

That way we could begin to treat this as a properly abstract programming
language. It could of course lead to utter confusion.
Robin Becker

More information about the Python-list mailing list