Skip to content

Commit 538e7e6

Browse files
authored
Revert "Imporves __div__ with __future__ import on py2 (#11276)" (#11741)
This reverts commit e6b91bd. See #11740 for the context.
1 parent b2c9296 commit 538e7e6

File tree

4 files changed

+5
-39
lines changed

4 files changed

+5
-39
lines changed

mypy/build.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -2188,11 +2188,8 @@ def type_checker(self) -> TypeChecker:
21882188
if not self._type_checker:
21892189
assert self.tree is not None, "Internal error: must be called on parsed file only"
21902190
manager = self.manager
2191-
self._type_checker = TypeChecker(
2192-
manager.errors, manager.modules, self.options,
2193-
self.tree, self.xpath, manager.plugin,
2194-
self.manager.semantic_analyzer.future_import_flags,
2195-
)
2191+
self._type_checker = TypeChecker(manager.errors, manager.modules, self.options,
2192+
self.tree, self.xpath, manager.plugin)
21962193
return self._type_checker
21972194

21982195
def type_map(self) -> Dict[Expression, Type]:

mypy/checker.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,8 @@ class TypeChecker(NodeVisitor[None], CheckerPluginInterface):
221221
# functions such as open(), etc.
222222
plugin: Plugin
223223

224-
# Future flags that we get from semantic analyzer.
225-
future_import_flags: Set[str]
226-
227224
def __init__(self, errors: Errors, modules: Dict[str, MypyFile], options: Options,
228-
tree: MypyFile, path: str, plugin: Plugin,
229-
future_import_flags: Set[str]) -> None:
225+
tree: MypyFile, path: str, plugin: Plugin) -> None:
230226
"""Construct a type checker.
231227
232228
Use errors to report type check errors.
@@ -272,8 +268,6 @@ def __init__(self, errors: Errors, modules: Dict[str, MypyFile], options: Option
272268
# argument through various `checker` and `checkmember` functions.
273269
self._is_final_def = False
274270

275-
self.future_import_flags = future_import_flags
276-
277271
@property
278272
def type_context(self) -> List[Optional[Type]]:
279273
return self.expr_checker.type_context

mypy/checkexpr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,8 @@ def dangerous_comparison(self, left: Type, right: Type,
24142414

24152415
def get_operator_method(self, op: str) -> str:
24162416
if op == '/' and self.chk.options.python_version[0] == 2:
2417-
return '__truediv__' if 'division' in self.chk.future_import_flags else '__div__'
2417+
# TODO also check for "from __future__ import division"
2418+
return '__div__'
24182419
else:
24192420
return operators.op_methods[op]
24202421

test-data/unit/check-expressions.test

-26
Original file line numberDiff line numberDiff line change
@@ -202,32 +202,6 @@ class C:
202202
pass
203203
[builtins fixtures/tuple.pyi]
204204

205-
[case testDivPython2]
206-
# flags: --python-version 2.7
207-
class A(object):
208-
def __div__(self, other):
209-
# type: (A, str) -> str
210-
return 'a'
211-
212-
a = A()
213-
reveal_type(a / 'b') # N: Revealed type is "builtins.str"
214-
a / 1 # E: Unsupported operand types for / ("A" and "int")
215-
[builtins fixtures/bool.pyi]
216-
217-
[case testDivPython2FutureImport]
218-
# flags: --python-version 2.7
219-
from __future__ import division
220-
221-
class A(object):
222-
def __truediv__(self, other):
223-
# type: (A, str) -> str
224-
return 'a'
225-
226-
a = A()
227-
reveal_type(a / 'b') # N: Revealed type is "builtins.str"
228-
a / 1 # E: Unsupported operand types for / ("A" and "int")
229-
[builtins fixtures/bool.pyi]
230-
231205
[case testIntDiv]
232206
a, b, c = None, None, None # type: (A, B, C)
233207
if int():

0 commit comments

Comments
 (0)