|
17 | 17 | CONTRAVARIANT,
|
18 | 18 | COVARIANT,
|
19 | 19 | ArgKind,
|
| 20 | + Block, |
| 21 | + ClassDef, |
| 22 | + SymbolTable, |
20 | 23 | TypeInfo,
|
21 | 24 | )
|
22 | 25 | from mypy.types import (
|
@@ -1018,25 +1021,18 @@ def visit_callable_type(self, template: CallableType) -> list[Constraint]:
|
1018 | 1021 | param_spec = template.param_spec()
|
1019 | 1022 |
|
1020 | 1023 | template_ret_type, cactual_ret_type = template.ret_type, cactual.ret_type
|
1021 |
| - bool_type = UnionType( |
1022 |
| - [LiteralType(True, cactual_ret_type), LiteralType(False, cactual_ret_type)] # type: ignore[arg-type] |
1023 |
| - ) |
1024 | 1024 |
|
1025 | 1025 | if template.type_guard is not None and cactual.type_guard is not None:
|
1026 | 1026 | template_ret_type = template.type_guard
|
1027 | 1027 | cactual_ret_type = cactual.type_guard
|
1028 | 1028 | elif template.type_guard is not None:
|
1029 | 1029 | template_ret_type = AnyType(TypeOfAny.special_form)
|
1030 |
| - elif cactual.type_guard is not None: |
1031 |
| - cactual_ret_type = bool_type |
1032 | 1030 |
|
1033 | 1031 | if template.type_is is not None and cactual.type_is is not None:
|
1034 | 1032 | template_ret_type = template.type_is
|
1035 | 1033 | cactual_ret_type = cactual.type_is
|
1036 | 1034 | elif template.type_is is not None:
|
1037 | 1035 | template_ret_type = AnyType(TypeOfAny.special_form)
|
1038 |
| - elif cactual.type_is is not None: |
1039 |
| - cactual_ret_type = bool_type |
1040 | 1036 |
|
1041 | 1037 | res.extend(infer_constraints(template_ret_type, cactual_ret_type, self.direction))
|
1042 | 1038 |
|
@@ -1340,6 +1336,40 @@ def visit_type_type(self, template: TypeType) -> list[Constraint]:
|
1340 | 1336 | else:
|
1341 | 1337 | return []
|
1342 | 1338 |
|
| 1339 | + def _make_type_info( |
| 1340 | + self, |
| 1341 | + name: str, |
| 1342 | + module_name: str | None = None, |
| 1343 | + mro: list[TypeInfo] | None = None, |
| 1344 | + bases: list[Instance] | None = None, |
| 1345 | + ) -> TypeInfo: |
| 1346 | + """Make a TypeInfo suitable for use in unit tests.""" |
| 1347 | + |
| 1348 | + class_def = ClassDef(name, Block([]), None, []) |
| 1349 | + class_def.fullname = name |
| 1350 | + |
| 1351 | + if module_name is None: |
| 1352 | + if "." in name: |
| 1353 | + module_name = name.rsplit(".", 1)[0] |
| 1354 | + else: |
| 1355 | + module_name = "__main__" |
| 1356 | + |
| 1357 | + info = TypeInfo(SymbolTable(), class_def, module_name) |
| 1358 | + if mro is None: |
| 1359 | + mro = [] |
| 1360 | + if name != "builtins.object": |
| 1361 | + mro.append(self.oi) |
| 1362 | + info.mro = [info] + mro |
| 1363 | + if bases is None: |
| 1364 | + if mro: |
| 1365 | + # By default, assume that there is a single non-generic base. |
| 1366 | + bases = [Instance(mro[0], [])] |
| 1367 | + else: |
| 1368 | + bases = [] |
| 1369 | + info.bases = bases |
| 1370 | + |
| 1371 | + return info |
| 1372 | + |
1343 | 1373 |
|
1344 | 1374 | def neg_op(op: int) -> int:
|
1345 | 1375 | """Map SubtypeOf to SupertypeOf and vice versa."""
|
|
0 commit comments