def gen_class_variable(self, cls: ClassDefinition, slot: SlotDefinition, can_be_positional: bool) -> str: """ Generate a class variable declaration for the supplied slot. Note: the can_be_positional attribute works, but it makes tag/value lists unduly complex, as you can't load them with tag=..., value=... -- you HAVE to load positionally. We currently ignore this parameter, meaning that we have a tag/value option for any BiolinkML element :param cls: Owning class :param slot: slot definition :param can_be_positional: True means that positional parameters are allowed. :return: Initializer string """ can_be_positional = False # Force everything to be tag values slotname = self.slot_name(slot.name) slot_range, default_val = self.range_cardinality( slot, cls, can_be_positional) ifabsent_text = ifabsent_value_declaration( slot.ifabsent, self, cls, slot) if slot.ifabsent is not None else None if ifabsent_text: default = f'= {ifabsent_text}' else: default = f'= {default_val}' if default_val else '' return f'''{slotname}: {slot_range} {default}'''
def gen_class_variable(self, cls: ClassDefinition, slot: SlotDefinition, can_be_positional: bool) -> str: """ Generate a class variable declaration for the supplied slot :param cls: Owning class :param slot: slot definition :param can_be_positional: True means that positional parameters are allowed :return: Initializer string """ slotname = self.slot_name(slot.name) slot_range, default_val = self.range_cardinality(slot, cls, can_be_positional) ifabsent_text = ifabsent_value_declaration(slot.ifabsent, self, cls, slot) if slot.ifabsent is not None else None if ifabsent_text: default = f'= {ifabsent_text}' else: default = f'= {default_val}' if default_val else '' return f'''{slotname}: {slot_range} {default}'''