Closed
Description
When I use from __future__ import division
, mypy looks for __div__
on objects instead of __truediv__
. Example code:
from __future__ import division
class ClassWithDiv(object):
def __div__(self, other):
# type: (ClassWithDiv) -> None
return None
class ClassWithTrueDiv(object):
def __truediv__(self, other):
# type: (ClassWithTrueDiv) -> None
return None
ClassWithDiv() / ClassWithDiv()
ClassWithTrueDiv() / ClassWithTrueDiv()
The actual output of running mypy --py2
:
$ mypy --py2 test_div.py
test_div.py:17: error: "ClassWithTrueDiv" has no attribute "__div__"
The expected output should be something like this:
test_div.py:16: error: "ClassWithDiv" has no attribute "__truediv__"
It would also be acceptable to give the same output as in Python 3 mode, which is:
$ mypy test_div.py
test_div.py:16: error: Unsupported left operand type for / ("ClassWithDiv")
I am using mypy from Git master. Version info:
$ mypy --version
mypy 0.640+dev-2244721df395ea7ccb986286a12594e2d7b097e8
$ python --version
Python 3.6.5
I am not using any mypy flags besides --py2
.