Complete the code to check if a function has a missing return statement during code review.
def check_return(func): source = func.__code__.co_code if [1] not in source: return False return True
The RETURN_VALUE opcode indicates a return statement in Python bytecode. Checking for it helps find missing returns.
Complete the code to identify if a variable name follows naming conventions during code review.
def is_valid_var(name): import re pattern = r'^[a-z_][a-z0-9_]*$' return bool(re.match([1], name))
The pattern '^[a-z_][a-z0-9_]*$' matches valid Python variable names starting with lowercase or underscore.
Fix the error in the code review function that checks for TODO comments in code.
def has_todo_comment(code_lines): for line in code_lines: if '[1]' in line: return True return False
Checking for "# TODO" ensures we find proper TODO comments with the hash symbol and uppercase TODO.
Fill both blanks to create a code review function that finds functions missing docstrings.
def missing_docstring(func): doc = func.__doc__ if doc is [1] or doc.strip() == [2]: return True return False
A function missing a docstring has __doc__ as None or an empty string "".
Fill all three blanks to create a code review snippet that collects all function names missing type hints.
def functions_missing_type_hints(module): missing = [] for name, func in module.__dict__.items(): if callable(func) and ([1] not in func.__annotations__ or [2] not in func.__annotations__): missing.append([3]) return missing
Type hints are stored in __annotations__ with keys for parameters and 'return'. Here, 'return' and 'param' are placeholders for keys, and name is appended.