Skip to content

Commit 80dd722

Browse files
committed
style: Add type annotation
1 parent 56e59d5 commit 80dd722

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/anagram.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
# Method 1: Using Sorting
9-
def are_anagrams_sorting(str1, str2):
9+
def are_anagrams_sorting(str1: str, str2: str) -> bool:
1010
"""
1111
Determines if two strings are anagrams by sorting.
1212
"""
@@ -19,7 +19,7 @@ def are_anagrams_sorting(str1, str2):
1919

2020

2121
# Method 2: Using Character Count with defaultdict for both strings
22-
def are_anagrams_dict(str1, str2):
22+
def are_anagrams_dict(str1: str, str2: str) -> bool:
2323
"""Determines if two strings are anagrams by counting characters with defaultdict for both strings."""
2424
# Remove whitespace and convert to lowercase for case-insensitive comparison
2525
str1 = str1.replace(" ", "").lower()
@@ -43,7 +43,7 @@ def are_anagrams_dict(str1, str2):
4343

4444

4545
# Method 3: Using Character Count with Array (assuming ASCII characters)
46-
def are_anagrams_array(str1, str2):
46+
def are_anagrams_array(str1: str, str2: str) -> bool:
4747
"""Determines if two strings are anagrams by counting characters with an array.
4848
4949
Assumes only ASCII characters.

test/test_anagram.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test cases for the anagram module."""
2+
# mypy: ignore-errors
23

34
import unittest
45

@@ -30,7 +31,7 @@ def test_are_anagrams_sorting(self):
3031
f"Failed for {str1} and {str2}",
3132
)
3233

33-
def test_are_anagrams_dict(self):
34+
def test_are_anagrams_dict(self) -> None:
3435
"""Test the are_anagrams_dict function."""
3536
for str1, str2, expected in self.test_cases:
3637
with self.subTest(str1=str1, str2=str2):
@@ -40,7 +41,7 @@ def test_are_anagrams_dict(self):
4041
f"Failed for {str1} and {str2}",
4142
)
4243

43-
def test_are_anagrams_array(self):
44+
def test_are_anagrams_array(self) -> None:
4445
"""Test the are_anagrams_array function."""
4546
for str1, str2, expected in self.test_cases:
4647
with self.subTest(str1=str1, str2=str2):

0 commit comments

Comments
 (0)