all "is" replaced with "==" (#14209)

Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
This commit is contained in:
Kalyani
2026-03-09 09:45:03 +05:30
committed by GitHub
parent 84b59c8781
commit 6f9f4318af

View File

@@ -15,14 +15,14 @@ test_data = {
"AB": False,
}
# Ensure our test data is valid
assert all((key == key[::-1]) is value for key, value in test_data.items())
assert all((key == key[::-1]) == value for key, value in test_data.items())
def is_palindrome(s: str) -> bool:
"""
Return True if s is a palindrome otherwise return False.
>>> all(is_palindrome(key) is value for key, value in test_data.items())
>>> all(is_palindrome(key) == value for key, value in test_data.items())
True
"""
@@ -41,7 +41,7 @@ def is_palindrome_traversal(s: str) -> bool:
"""
Return True if s is a palindrome otherwise return False.
>>> all(is_palindrome_traversal(key) is value for key, value in test_data.items())
>>> all(is_palindrome_traversal(key) == value for key, value in test_data.items())
True
"""
end = len(s) // 2
@@ -60,7 +60,7 @@ def is_palindrome_recursive(s: str) -> bool:
"""
Return True if s is a palindrome otherwise return False.
>>> all(is_palindrome_recursive(key) is value for key, value in test_data.items())
>>> all(is_palindrome_recursive(key) == value for key, value in test_data.items())
True
"""
if len(s) <= 1:
@@ -75,14 +75,14 @@ def is_palindrome_slice(s: str) -> bool:
"""
Return True if s is a palindrome otherwise return False.
>>> all(is_palindrome_slice(key) is value for key, value in test_data.items())
>>> all(is_palindrome_slice(key) == value for key, value in test_data.items())
True
"""
return s == s[::-1]
def benchmark_function(name: str) -> None:
stmt = f"all({name}(key) is value for key, value in test_data.items())"
stmt = f"all({name}(key) == value for key, value in test_data.items())"
setup = f"from __main__ import test_data, {name}"
number = 500000
result = timeit(stmt=stmt, setup=setup, number=number)
@@ -91,8 +91,8 @@ def benchmark_function(name: str) -> None:
if __name__ == "__main__":
for key, value in test_data.items():
assert is_palindrome(key) is is_palindrome_recursive(key)
assert is_palindrome(key) is is_palindrome_slice(key)
assert is_palindrome(key) == is_palindrome_recursive(key)
assert is_palindrome(key) == is_palindrome_slice(key)
print(f"{key:21} {value}")
print("a man a plan a canal panama")