Add getter and/or setter for attribute if defined as property in a base class. Only add declarations. The body IR will be synthesized later during irbuild.
(
info: TypeInfo,
ir: ClassIR,
attr_name: str,
attr_rtype: RType,
module_name: str,
mapper: Mapper,
)
| 599 | |
| 600 | |
| 601 | def add_property_methods_for_attribute_if_needed( |
| 602 | info: TypeInfo, |
| 603 | ir: ClassIR, |
| 604 | attr_name: str, |
| 605 | attr_rtype: RType, |
| 606 | module_name: str, |
| 607 | mapper: Mapper, |
| 608 | ) -> None: |
| 609 | """Add getter and/or setter for attribute if defined as property in a base class. |
| 610 | |
| 611 | Only add declarations. The body IR will be synthesized later during irbuild. |
| 612 | """ |
| 613 | for base in info.mro[1:]: |
| 614 | if base in mapper.type_to_ir: |
| 615 | base_ir = mapper.type_to_ir[base] |
| 616 | n = base.names.get(attr_name) |
| 617 | if n is None: |
| 618 | continue |
| 619 | node = n.node |
| 620 | if isinstance(node, Decorator) and node.name not in ir.method_decls: |
| 621 | # Defined as a read-only property in base class/trait |
| 622 | add_getter_declaration(ir, attr_name, attr_rtype, module_name) |
| 623 | elif isinstance(node, OverloadedFuncDef) and is_valid_multipart_property_def(node): |
| 624 | # Defined as a read-write property in base class/trait |
| 625 | add_getter_declaration(ir, attr_name, attr_rtype, module_name) |
| 626 | add_setter_declaration(ir, attr_name, attr_rtype, module_name) |
| 627 | elif base_ir.is_trait and attr_rtype.error_overlap: |
| 628 | add_getter_declaration(ir, attr_name, attr_rtype, module_name) |
| 629 | add_setter_declaration(ir, attr_name, attr_rtype, module_name) |
| 630 | |
| 631 | |
| 632 | def add_getter_declaration( |
no test coverage detected
searching dependent graphs…