Changing the Division Operator -- PEP 238, rev 1.12

Guido van Rossum guido at python.org
Sat Jul 28 11:42:28 EDT 2001


paul at svensson.org (Paul Svensson) writes:

> Consider an existing
> 	class Foo:
> 	    def __div__(self, other):
> 		...
> 
> With your proposal, this will break as soon as it's called from
> a module importing the future division.

And that's exactly right, because we don't know if the type is trying
to "look like" a float or an int, so we don't know whether to map
__floordiv__ to __div__ or __truediv__.

This is only a problem when the user of the class uses true or floor
division, and I think it's fair that the system shouldn't attempt to
guess.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list