From e553d07c349ab573bdfb74417a87a2767878dd24 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Tue, 23 Sep 2025 10:23:49 -0700 Subject: [PATCH 1/2] demo --- codeflash/result/common_tags.py | 12 ++++++++++++ tests/test_common_tags.py | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 codeflash/result/common_tags.py create mode 100644 tests/test_common_tags.py diff --git a/codeflash/result/common_tags.py b/codeflash/result/common_tags.py new file mode 100644 index 000000000..6ac8b2f2f --- /dev/null +++ b/codeflash/result/common_tags.py @@ -0,0 +1,12 @@ +from __future__ import annotations + + +def find_common_tags(articles: list[dict[str, list[str]]]) -> set[str]: + if not articles: + return set() + + common_tags = articles[0].get("tags", []) + for article in articles[1:]: + common_tags = [tag for tag in common_tags if tag in article.get("tags", [])] + return set(common_tags) + \ No newline at end of file diff --git a/tests/test_common_tags.py b/tests/test_common_tags.py new file mode 100644 index 000000000..ce5bda359 --- /dev/null +++ b/tests/test_common_tags.py @@ -0,0 +1,23 @@ +from codeflash.result.common_tags import find_common_tags + + +def test_common_tags_1() -> None: + articles_1 = [ + {"title": "Article 1", "tags": ["Python", "AI", "ML"]}, + {"title": "Article 2", "tags": ["Python", "Data Science", "AI"]}, + {"title": "Article 3", "tags": ["Python", "AI", "Big Data"]}, + ] + + expected = {"Python", "AI"} + + assert find_common_tags(articles_1) == expected + + articles_2 = [ + {"title": "Article 1", "tags": ["Python", "AI", "ML"]}, + {"title": "Article 2", "tags": ["Python", "Data Science", "AI"]}, + {"title": "Article 3", "tags": ["Python", "AI", "Big Data"]}, + {"title": "Article 4", "tags": ["Python", "AI", "ML"]}, + ] + + assert find_common_tags(articles_2) == expected + \ No newline at end of file From ad73bb31798af20afc62495b371ac4fb79f66154 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Tue, 23 Sep 2025 10:24:54 -0700 Subject: [PATCH 2/2] fix --- codeflash/result/common_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/result/common_tags.py b/codeflash/result/common_tags.py index 6ac8b2f2f..b800cf314 100644 --- a/codeflash/result/common_tags.py +++ b/codeflash/result/common_tags.py @@ -7,6 +7,6 @@ def find_common_tags(articles: list[dict[str, list[str]]]) -> set[str]: common_tags = articles[0].get("tags", []) for article in articles[1:]: - common_tags = [tag for tag in common_tags if tag in article.get("tags", [])] + common_tags = [tag for tag in common_tags if tag in article.get("tags", [])] return set(common_tags) \ No newline at end of file