[New-bugs-announce] [issue13137] from __future__ import division breaks ad hoc numeric types

Blair report at bugs.python.org
Sun Oct 9 00:58:37 CEST 2011


New submission from Blair <bidihall at gmail.com>:

I believe that the use of __future__.division may have unintended consequences with user types that define division.

The following fails:

	from __future__ import division

	class NumericType(object):
		def __init__(self,x):
			self.x = x

		def __div__(self,rhs):
			return self.x/rhs

	print NumericType(3.0) / 2.0

with the error message

  File "C:\proj_py\learning\future_bug\future.py", line 10, in <module>
    print NumericType(3.0) / 2.0
TypeError: unsupported operand type(s) for /: 'NumericType' and 'float'

Remove the line `from __future__ import division` and everything works fine.

I am using Python 2.7.2

----------
components: None
messages: 145195
nosy: gumtree
priority: normal
severity: normal
status: open
title: from __future__ import division breaks ad hoc numeric types
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13137>
_______________________________________


More information about the New-bugs-announce mailing list