Generate error message for individual incompatible tuple pairs
(
self,
lhs_types: list[Type],
rhs_types: list[Type],
context: Context,
msg: message_registry.ErrorMessage,
)
| 2516 | return format_type(typ, self.options) |
| 2517 | |
| 2518 | def generate_incompatible_tuple_error( |
| 2519 | self, |
| 2520 | lhs_types: list[Type], |
| 2521 | rhs_types: list[Type], |
| 2522 | context: Context, |
| 2523 | msg: message_registry.ErrorMessage, |
| 2524 | ) -> None: |
| 2525 | """Generate error message for individual incompatible tuple pairs""" |
| 2526 | error_cnt = 0 |
| 2527 | notes: list[str] = [] |
| 2528 | for i, (lhs_t, rhs_t) in enumerate(zip(lhs_types, rhs_types)): |
| 2529 | if not is_subtype(rhs_t, lhs_t): |
| 2530 | if error_cnt < 3: |
| 2531 | notes.append( |
| 2532 | "Expression tuple item {} has type {}; {} expected; ".format( |
| 2533 | str(i), |
| 2534 | format_type(rhs_t, self.options), |
| 2535 | format_type(lhs_t, self.options), |
| 2536 | ) |
| 2537 | ) |
| 2538 | error_cnt += 1 |
| 2539 | |
| 2540 | info = f" ({str(error_cnt)} tuple items are incompatible" |
| 2541 | if error_cnt - 3 > 0: |
| 2542 | info += f"; {str(error_cnt - 3)} items are omitted)" |
| 2543 | else: |
| 2544 | info += ")" |
| 2545 | msg = msg.with_additional_msg(info) |
| 2546 | self.fail(msg.value, context, code=msg.code) |
| 2547 | for note in notes: |
| 2548 | self.note(note, context, code=msg.code) |
| 2549 | |
| 2550 | def add_fixture_note(self, fullname: str, ctx: Context) -> None: |
| 2551 | self.note(f'Maybe your test fixture does not define "{fullname}"?', ctx) |
no test coverage detected