Check a method override with given signatures. Arguments: override: The signature of the overriding method. original: The signature of the original supertype method. name: The name of the overriding method.
(
self,
override: FunctionLike,
original: FunctionLike,
name: str,
name_in_super: str,
supertype: str,
original_class_or_static: bool,
override_class_or_static: bool,
node: Context,
)
| 2590 | assert False, "Need to check all FunctionLike subtypes here" |
| 2591 | |
| 2592 | def check_override( |
| 2593 | self, |
| 2594 | override: FunctionLike, |
| 2595 | original: FunctionLike, |
| 2596 | name: str, |
| 2597 | name_in_super: str, |
| 2598 | supertype: str, |
| 2599 | original_class_or_static: bool, |
| 2600 | override_class_or_static: bool, |
| 2601 | node: Context, |
| 2602 | ) -> bool: |
| 2603 | """Check a method override with given signatures. |
| 2604 | |
| 2605 | Arguments: |
| 2606 | override: The signature of the overriding method. |
| 2607 | original: The signature of the original supertype method. |
| 2608 | name: The name of the overriding method. |
| 2609 | Used primarily for generating error messages. |
| 2610 | name_in_super: The name of the overridden in the superclass. |
| 2611 | Used for generating error messages only. |
| 2612 | supertype: The name of the supertype. |
| 2613 | original_class_or_static: Indicates whether the original method (from the superclass) |
| 2614 | is either a class method or a static method. |
| 2615 | override_class_or_static: Indicates whether the overriding method (from the subclass) |
| 2616 | is either a class method or a static method. |
| 2617 | node: Context node. |
| 2618 | """ |
| 2619 | # Use boolean variable to clarify code. |
| 2620 | fail = False |
| 2621 | op_method_wider_note = False |
| 2622 | if not is_subtype(override, original, ignore_pos_arg_names=True): |
| 2623 | fail = True |
| 2624 | elif isinstance(override, Overloaded) and self.is_forward_op_method(name): |
| 2625 | # Operator method overrides cannot extend the domain, as |
| 2626 | # this could be unsafe with reverse operator methods. |
| 2627 | original_domain = self.get_op_other_domain(original) |
| 2628 | override_domain = self.get_op_other_domain(override) |
| 2629 | if ( |
| 2630 | original_domain |
| 2631 | and override_domain |
| 2632 | and not is_subtype(override_domain, original_domain) |
| 2633 | ): |
| 2634 | fail = True |
| 2635 | op_method_wider_note = True |
| 2636 | if isinstance(override, FunctionLike): |
| 2637 | if original_class_or_static and not override_class_or_static: |
| 2638 | fail = True |
| 2639 | elif isinstance(original, CallableType) and isinstance(override, CallableType): |
| 2640 | if original.type_guard is not None and override.type_guard is None: |
| 2641 | fail = True |
| 2642 | if original.type_is is not None and override.type_is is None: |
| 2643 | fail = True |
| 2644 | |
| 2645 | if is_private(name): |
| 2646 | fail = False |
| 2647 | |
| 2648 | if fail: |
| 2649 | emitted_msg = False |
no test coverage detected