feat: Add user utility#88
Conversation
|
@snipercodeai review |
| @@ -0,0 +1,9 @@ | |||
| def get_user(users: list, user_id: int) -> dict: | |||
There was a problem hiding this comment.
Type hinting: The users parameter is hinted as a list, but its contents are dictionaries. Consider using list[dict] for better type hinting.
| @@ -0,0 +1,9 @@ | |||
| def get_user(users: list, user_id: int) -> dict: | |||
| for user in users: | |||
| if user["id"] == user_id: | |||
There was a problem hiding this comment.
Potential Bug: This function will return None if no user with the given user_id is found. Consider raising a ValueError or returning an empty dictionary instead.
|
|
||
|
|
||
| def get_username(users: list, user_id: int) -> str: | ||
| user = get_user(users, user_id) |
There was a problem hiding this comment.
Bug: If get_user returns None, this line will raise a TypeError. Add a null check: if user is None: raise ValueError('User not found') or handle it in the get_user function as suggested above.
|
|
||
| def get_username(users: list, user_id: int) -> str: | ||
| user = get_user(users, user_id) | ||
| return user["name"].upper() |
There was a problem hiding this comment.
Potential Bug: This line will raise a TypeError if user is None. Add a null check: if user is not None and 'name' in user: return user['name'].upper() to handle cases where the user or the 'name' key is missing.
| return user | ||
|
|
||
|
|
||
| def get_username(users: list, user_id: int) -> str: |
There was a problem hiding this comment.
Function signature: The function get_username could be improved by adding a docstring to describe its purpose and parameters. Consider using a tool like Sphinx for documentation.
|
Good stuff. A bit noisy on the docs but it did it. |
No description provided.