|
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 ( |
@@ -1026,25 +1029,18 @@ def visit_callable_type(self, template: CallableType) -> list[Constraint]: |
1026 | 1029 | param_spec = template.param_spec() |
1027 | 1030 |
|
1028 | 1031 | template_ret_type, cactual_ret_type = template.ret_type, cactual.ret_type |
1029 | | - bool_type = UnionType( |
1030 | | - [LiteralType(True, cactual_ret_type), LiteralType(False, cactual_ret_type)] # type: ignore[arg-type] |
1031 | | - ) |
1032 | 1032 |
|
1033 | 1033 | if template.type_guard is not None and cactual.type_guard is not None: |
1034 | 1034 | template_ret_type = template.type_guard |
1035 | 1035 | cactual_ret_type = cactual.type_guard |
1036 | 1036 | elif template.type_guard is not None: |
1037 | 1037 | template_ret_type = AnyType(TypeOfAny.special_form) |
1038 | | - elif cactual.type_guard is not None: |
1039 | | - cactual_ret_type = bool_type |
1040 | 1038 |
|
1041 | 1039 | if template.type_is is not None and cactual.type_is is not None: |
1042 | 1040 | template_ret_type = template.type_is |
1043 | 1041 | cactual_ret_type = cactual.type_is |
1044 | 1042 | elif template.type_is is not None: |
1045 | 1043 | template_ret_type = AnyType(TypeOfAny.special_form) |
1046 | | - elif cactual.type_is is not None: |
1047 | | - cactual_ret_type = bool_type |
1048 | 1044 |
|
1049 | 1045 | res.extend(infer_constraints(template_ret_type, cactual_ret_type, self.direction)) |
1050 | 1046 |
|
@@ -1352,6 +1348,40 @@ def visit_type_type(self, template: TypeType) -> list[Constraint]: |
1352 | 1348 | else: |
1353 | 1349 | return [] |
1354 | 1350 |
|
| 1351 | + def _make_type_info( |
| 1352 | + self, |
| 1353 | + name: str, |
| 1354 | + module_name: str | None = None, |
| 1355 | + mro: list[TypeInfo] | None = None, |
| 1356 | + bases: list[Instance] | None = None, |
| 1357 | + ) -> TypeInfo: |
| 1358 | + """Make a TypeInfo suitable for use in unit tests.""" |
| 1359 | + |
| 1360 | + class_def = ClassDef(name, Block([]), None, []) |
| 1361 | + class_def.fullname = name |
| 1362 | + |
| 1363 | + if module_name is None: |
| 1364 | + if "." in name: |
| 1365 | + module_name = name.rsplit(".", 1)[0] |
| 1366 | + else: |
| 1367 | + module_name = "__main__" |
| 1368 | + |
| 1369 | + info = TypeInfo(SymbolTable(), class_def, module_name) |
| 1370 | + if mro is None: |
| 1371 | + mro = [] |
| 1372 | + if name != "builtins.object": |
| 1373 | + mro.append(self.oi) |
| 1374 | + info.mro = [info] + mro |
| 1375 | + if bases is None: |
| 1376 | + if mro: |
| 1377 | + # By default, assume that there is a single non-generic base. |
| 1378 | + bases = [Instance(mro[0], [])] |
| 1379 | + else: |
| 1380 | + bases = [] |
| 1381 | + info.bases = bases |
| 1382 | + |
| 1383 | + return info |
| 1384 | + |
1355 | 1385 |
|
1356 | 1386 | def neg_op(op: int) -> int: |
1357 | 1387 | """Map SubtypeOf to SupertypeOf and vice versa.""" |
|
0 commit comments