-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Demo: Code review #559
base: main
Are you sure you want to change the base?
Demo: Code review #559
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||||||||||||
import random | ||||||||||||||||
import time | ||||||||||||||||
|
||||||||||||||||
# Global variable | ||||||||||||||||
GLOBAL_COUNTER = 0 | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def process_data(data): | ||||||||||||||||
global GLOBAL_COUNTER | ||||||||||||||||
result = [] | ||||||||||||||||
for i in range(len(data)): | ||||||||||||||||
item = data[i] | ||||||||||||||||
if item % 2 == 0: | ||||||||||||||||
result.append(item * 2) | ||||||||||||||||
else: | ||||||||||||||||
result.append(item * 3) | ||||||||||||||||
GLOBAL_COUNTER += 1 | ||||||||||||||||
return result | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def fetch_user_data(user_id): | ||||||||||||||||
# Simulating a database query | ||||||||||||||||
time.sleep(2) | ||||||||||||||||
return {"id": user_id, "name": f"User{user_id}", "score": random.randint(1, 100)} | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def calculate_average(numbers): | ||||||||||||||||
total = 0 | ||||||||||||||||
count = 0 | ||||||||||||||||
for num in numbers: | ||||||||||||||||
total += num | ||||||||||||||||
count += 1 | ||||||||||||||||
return total / count if count > 0 else 0 | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def write_to_file(filename, content): | ||||||||||||||||
f = open(filename, "w") | ||||||||||||||||
f.write(content) | ||||||||||||||||
f.close() | ||||||||||||||||
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment: File not closed properly in write_to_file function Solution: Use a 'with' statement to ensure the file is properly closed.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def main(): | ||||||||||||||||
data = [1, 2, 3, 4, 5] | ||||||||||||||||
processed_data = process_data(data) | ||||||||||||||||
print("Processed data:", processed_data) | ||||||||||||||||
|
||||||||||||||||
user_data = fetch_user_data(123) | ||||||||||||||||
print("User data:", user_data) | ||||||||||||||||
|
||||||||||||||||
numbers = [10, 20, 30, 40, 50] | ||||||||||||||||
avg = calculate_average(numbers) | ||||||||||||||||
print("Average:", avg) | ||||||||||||||||
|
||||||||||||||||
write_to_file("output.txt", "Hello, World!") | ||||||||||||||||
|
||||||||||||||||
unused_var = 42 | ||||||||||||||||
print("Unused variable:", unused_var) | ||||||||||||||||
|
||||||||||||||||
db_password = "password123" | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment: Hardcoded database password in plain text Solution: Use environment variables or a secure configuration management system to store sensitive information.
Suggested change
|
||||||||||||||||
print("DB Password:", db_password) | ||||||||||||||||
|
||||||||||||||||
squared_numbers = [num * num for num in range(100)] | ||||||||||||||||
print("Squared numbers:", squared_numbers) | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: Inefficient list processing in process_data function
Solution: Use a list comprehension or direct iteration over the data list.