[Python-bugs-list] [ python-Bugs-450909 ] __future__.division fails at prompt

noreply@sourceforge.net noreply@sourceforge.net
Wed, 15 Aug 2001 05:19:47 -0700


Bugs item #450909, was opened at 2001-08-14 12:20
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=450909&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Fred L. Drake, Jr. (fdrake)
Assigned to: Jeremy Hylton (jhylton)
Summary: __future__.division fails at prompt

Initial Comment:
At the interactive prompt, this should use the __truediv__() method to implement division, not __div__():

>>> from __future__ import division
>>> class C:
...   def __div__(self, other):
...     return self
...
>>> c = C()
>>> c / 1
<__main__.C instance at 0x81aede4>

# This should have raised TypeError

>>> class C:
...   def __div__(self, other):
...     return 1.0
...   def __truediv__(self, other):
...     return 2.0
...
>>> c2 = C()
>>> c2 / 1
1.0

# This should have returned 2.0

Appearantly a flag isn't being maintained with the global state.  This is using the CVS version of Python as of 10 minutes ago.

----------------------------------------------------------------------

Comment By: Jeremy Hylton (jhylton)
Date: 2001-08-14 13:03

Message:
Logged In: YES 
user_id=31392

Fixed in rev 2.217 of compile.c


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-14 12:28

Message:
Logged In: YES 
user_id=6380

Also note that this *used* to work.  Here's a different
version I built on August 10:

>>> from __future__ import division
>>> 1/3
0.33333333333333331
>>> 


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-14 12:26

Message:
Logged In: YES 
user_id=6380

Note that the problem happens even for built-in types:

(Current CVS)
>>> from __future__ import division
>>> 3/2
1
>>> 


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=450909&group_id=5470