timtadh / zhang-shasha

Tree edit distance using the Zhang Shasha algorithm
Other
433 stars 63 forks source link

Operation.__repr__ fails if nodes have no label attribute #45

Closed smola closed 4 years ago

smola commented 6 years ago

When using custom nodes without a label attribute, Operationrepr will fail:

    def __repr__(self):
        if self.type == self.remove:
            return '<Operation Remove: ' + self.arg1.label + '>'
        elif self.type == self.insert:
            return '<Operation Insert: ' + self.arg2.label + '>'
        elif self.type == self.update:
>           return '<Operation Update: ' + self.arg1.label + ' to ' + self.arg2.label + '>'
E           AttributeError: 'Node' object has no attribute 'label'
timtadh commented 6 years ago

Ack. I think the __repr__ should be used for those nodes to let them stringify themselves. What do you think? (Sorry for the slow response, I somehow missed this issue).

smola commented 6 years ago

@timtadh Yes, I think that would make sense. In my case I just got around the issue by not relying on Operation.repr at all.

BramVanroy commented 5 years ago

I agree that printing operation is useful to get an idee what's being operated on. Perhaps it's better to just save the nodes themselves instead of their (possibly non-existant) .label.