Skip to content

Commit 46bac17

Browse files
Preserve tag order when deduplicating in validate_tags
1 parent 09839b8 commit 46bac17

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ def validate_tags(tags, filename=None) -> list[str]:
6666
filename: Optional filename for better error messages
6767
6868
Returns:
69-
List of normalized (lowercase) tags
69+
List of normalized (lowercase) tags with duplicates removed.
70+
Original order is preserved.
7071
7172
Raises:
7273
ValueError: If tags are invalid (wrong type, empty list, contain whitespace, etc.)
7374
7475
Note:
75-
An empty tags list (tags: []) is considered invalid. If you have no tags,
76-
omit the 'tags' field entirely from the frontmatter.
76+
- An empty tags list (tags: []) is considered invalid. If you have no tags,
77+
omit the 'tags' field entirely from the frontmatter.
78+
- Duplicate tags (after normalization) are automatically removed while
79+
preserving the order of first occurrence.
7780
"""
7881
context = f" in {filename}" if filename else ""
7982

@@ -96,7 +99,7 @@ def validate_tags(tags, filename=None) -> list[str]:
9699

97100
normalized.append(tag.lower())
98101

99-
return list(set(normalized))
102+
return list(dict.fromkeys(normalized))
100103

101104

102105
def get_version_from_pyproject() -> str:

0 commit comments

Comments
 (0)