Keep TableAnnotation type when a line is split - #570
FedyaBadyilo wants to merge 2 commits into
Conversation
| selected = AbstractStructureExtractor._select_annotations(annotations, 0, 9) | ||
| table_anns = [ann for ann in selected if ann.name == TableAnnotation.name] | ||
| self.assertEqual(2, len(table_anns)) | ||
| self.assertTrue(all(isinstance(ann, TableAnnotation) for ann in table_anns)) |
There was a problem hiding this comment.
У нас нет обязательного требования к тому, чтобы аннотации были соответствующего класса, важно лишь название, так как AnnotationMerger все равно эту информацию удаляет. Это не очень хорошо, и в будущем мы планируем пересмотреть аннотирование в принципе. Я бы удалила эту строку теста
| for annotation in annotations: | ||
| if annotation.name in [TableAnnotation.name, AttachAnnotation.name]: | ||
| if start == 0: | ||
| new_annotation = Annotation(start=start, end=end, value=annotation.value, name=annotation.name) |
There was a problem hiding this comment.
Проблема этой строки не в том, что мы теряем информацию о типе класса, а в том, что мы не сохраняем поле annotation.is_mergeable при создании новой аннотации. У Annotation по умолчанию is_mergeable = True, для TableAnnotation и AttachAnnotation is_mergeable = False. Достаточно это исправить, и написанный тест будет проходить
|
|
||
| def test_select_annotations_keeps_multiple_tables_after_merge(self) -> None: | ||
| """Two tables on one line must both survive a slice and AnnotationMerger.""" | ||
| text = "Заголовок и текст" |
There was a problem hiding this comment.
minor: переменная не используется
Summary
_select_annotationsnow copies table and attachment marks asTableAnnotation/AttachAnnotationinstead of a genericAnnotation.AnnotationMergerno longer drops all but the first.Closes #569
Test plan
python -m unittest tests.unit_tests.test_misc_annotationsflake8 .