Preserve order of tags when cleaning

This commit is contained in:
Miroslav Kovar 2019-10-03 15:44:10 +02:00 committed by Lex Berezhny
parent 7cb03dde44
commit 3c96fda59b
3 changed files with 10 additions and 15 deletions

View file

@ -540,17 +540,11 @@ class TagList(BaseMessageList[str]):
__slots__ = ()
item_class = str
@classmethod
def create_normalized(cls, message):
message[:] = clean_tags(message)
return cls(message)
def append(self, tag: str):
tag = normalize_tag(tag)
if tag not in self._message:
self._message.append(tag)
if tag and tag not in self.message:
self.message.append(tag)
def extend(self, tags: List[str]):
tags = clean_tags(tags)
tags = list(set(tags).difference(set(self._message)))
self._message.extend(tags)
for tag in tags:
self.append(tag)

View file

@ -167,10 +167,6 @@ class BaseClaim:
def tags(self) -> List[str]:
return TagList(self.claim.message.tags)
@tags.setter
def tags(self, tags: List[str]):
self.claim.message.tags = TagList.create_normalized(tags)
@property
def languages(self) -> LanguageList:
return LanguageList(self.claim.message.languages)

View file

@ -10,4 +10,9 @@ def normalize_tag(tag: str):
def clean_tags(tags: List[str]):
return [tag for tag in set(normalize_tag(tag) for tag in tags) if tag]
clean = []
for ind, tag in enumerate(tags):
norm_tag = normalize_tag(tag)
if norm_tag and norm_tag not in clean[:ind]:
clean.append(norm_tag)
return clean