diff --git a/codereview-test b/codereview-test new file mode 100644 index 0000000..8fb732a --- /dev/null +++ b/codereview-test @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +""" +A simple calculator script with various errors for testing code review tools. +""" + +import os +import sys +import json # unused import + +def calculate_average(numbers): + # Missing input validation + total = 0 + for num in numbers: + total += num + # Division by zero potential + return total / len(numbers) + +def process_data(data): + # Undefined variable error + result = [] + for item in data: + if item > threshold: # threshold is not defined + result.append(item * 2) + return result + +class Calculator: + def __init__(self): + self.history = [] + + def add(self, a, b): + # Missing type hints and validation + result = a + b + self.history.append(result) + return result + + def divide(self, a, b): + # No zero division check + return a / b + + def get_history(self): + # Returning mutable reference + return self.history + +def main(): + # Syntax error - missing closing bracket + numbers = [1, 2, 3, 4, 5 + + # Logic error - wrong function name + avg = calculate_mean(numbers) # function is called calculate_average + print(f"Average: {avg}") + + # Unused variable + unused_var = "this is never used" + + # Inefficient loop + large_list = list(range(10000)) + squared = [] + for i in range(len(large_list)): # should use enumerate or direct iteration + squared.append(large_list[i] ** 2) + + # String concatenation in loop (inefficient) + message = "" + for i in range(100): + message += f"Item {i} " + + # Security issue - using eval + user_input = "2 + 2" + result = eval(user_input) + + # Missing exception handling + with open("nonexistent_file.txt", "r") as f: + content = f.read() + + calc = Calculator() + # Potential error - passing string to add method + calc.add("5", 3) + +if __name__ == "__main__": + main()