Populate attribute and method declarations.
(
cdef: ClassDef,
ir: ClassIR,
path: str,
module_name: str,
errors: Errors,
mapper: Mapper,
options: CompilerOptions,
)
| 528 | |
| 529 | |
| 530 | def prepare_methods_and_attributes( |
| 531 | cdef: ClassDef, |
| 532 | ir: ClassIR, |
| 533 | path: str, |
| 534 | module_name: str, |
| 535 | errors: Errors, |
| 536 | mapper: Mapper, |
| 537 | options: CompilerOptions, |
| 538 | ) -> None: |
| 539 | """Populate attribute and method declarations.""" |
| 540 | info = cdef.info |
| 541 | for name, node in info.names.items(): |
| 542 | # Currently all plugin generated methods are dummies and not included. |
| 543 | if node.plugin_generated: |
| 544 | continue |
| 545 | |
| 546 | if isinstance(node.node, Var): |
| 547 | assert node.node.type, "Class member %s missing type" % name |
| 548 | if not node.node.is_classvar and name not in ("__slots__", "__deletable__"): |
| 549 | attr_rtype = mapper.type_to_rtype(node.node.type) |
| 550 | if ir.is_trait and attr_rtype.error_overlap: |
| 551 | # Traits don't have attribute definedness bitmaps, so use |
| 552 | # property accessor methods to access attributes that need them. |
| 553 | # We will generate accessor implementations that use the class bitmap |
| 554 | # for any concrete subclasses. |
| 555 | add_getter_declaration(ir, name, attr_rtype, module_name) |
| 556 | add_setter_declaration(ir, name, attr_rtype, module_name) |
| 557 | ir.attributes[name] = attr_rtype |
| 558 | elif isinstance(node.node, (FuncDef, Decorator)): |
| 559 | prepare_method_def(ir, module_name, cdef, mapper, node.node, options) |
| 560 | elif isinstance(node.node, OverloadedFuncDef): |
| 561 | # Handle case for property with both a getter and a setter |
| 562 | if node.node.is_property: |
| 563 | if is_valid_multipart_property_def(node.node): |
| 564 | for item in node.node.items: |
| 565 | prepare_method_def(ir, module_name, cdef, mapper, item, options) |
| 566 | else: |
| 567 | errors.error("Unsupported property decorator semantics", path, cdef.line) |
| 568 | |
| 569 | # Handle case for regular function overload |
| 570 | else: |
| 571 | if not node.node.impl: |
| 572 | errors.error( |
| 573 | "Overloads without implementation are not supported", path, cdef.line |
| 574 | ) |
| 575 | else: |
| 576 | prepare_method_def(ir, module_name, cdef, mapper, node.node.impl, options) |
| 577 | |
| 578 | if ir.builtin_base: |
| 579 | ir.attributes.clear() |
| 580 | |
| 581 | |
| 582 | def prepare_implicit_property_accessors( |
no test coverage detected
searching dependent graphs…