MCPcopy Index your code
hub / github.com/python/mypy / try_report_long_tuple_assignment_error

Method try_report_long_tuple_assignment_error

mypy/messages.py:2461–2504  ·  view source on GitHub ↗

Try to generate meaningful error message for very long tuple assignment Returns a bool: True when generating long tuple assignment error, False when no such error reported

(
        self,
        subtype: ProperType,
        supertype: ProperType,
        context: Context,
        msg: message_registry.ErrorMessage,
        subtype_label: str | None = None,
        supertype_label: str | None = None,
    )

Source from the content-addressed store, hash-verified

2459 )
2460
2461 def try_report_long_tuple_assignment_error(
2462 self,
2463 subtype: ProperType,
2464 supertype: ProperType,
2465 context: Context,
2466 msg: message_registry.ErrorMessage,
2467 subtype_label: str | None = None,
2468 supertype_label: str | None = None,
2469 ) -> bool:
2470 """Try to generate meaningful error message for very long tuple assignment
2471
2472 Returns a bool: True when generating long tuple assignment error,
2473 False when no such error reported
2474 """
2475 if isinstance(subtype, TupleType):
2476 if (
2477 len(subtype.items) > MAX_TUPLE_ITEMS
2478 and isinstance(supertype, Instance)
2479 and supertype.type.fullname == "builtins.tuple"
2480 ):
2481 lhs_type = supertype.args[0]
2482 lhs_types = [lhs_type] * len(subtype.items)
2483 self.generate_incompatible_tuple_error(lhs_types, subtype.items, context, msg)
2484 return True
2485 elif isinstance(supertype, TupleType) and (
2486 len(subtype.items) > MAX_TUPLE_ITEMS or len(supertype.items) > MAX_TUPLE_ITEMS
2487 ):
2488 if len(subtype.items) != len(supertype.items):
2489 if supertype_label is not None and subtype_label is not None:
2490 msg = msg.with_additional_msg(
2491 " ({} {}, {} {})".format(
2492 subtype_label,
2493 self.format_long_tuple_type(subtype),
2494 supertype_label,
2495 self.format_long_tuple_type(supertype),
2496 )
2497 )
2498 self.fail(msg.value, context, code=msg.code)
2499 return True
2500 self.generate_incompatible_tuple_error(
2501 supertype.items, subtype.items, context, msg
2502 )
2503 return True
2504 return False
2505
2506 def format_long_tuple_type(self, typ: TupleType) -> str:
2507 """Format very long tuple type using an ellipsis notation"""

Callers 1

check_subtypeMethod · 0.80

Calls 7

failMethod · 0.95
isinstanceFunction · 0.85
lenFunction · 0.85
with_additional_msgMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected