Medium task: Implement Python module for optional tree stage wires
Task: Implement the Python module tree_stages_optional with a function that matches the tests.
What to implement and where:
Create a Python module at /app/tree_stages_optional.py (alternatively, a package at /app/tree_stages_optional/ with an __init__.py exporting declare_temp_wires).
Provide a function with the exact signature:
def declare_temp_wires(n: int) -> str
Required behavior and contract:
Type validation
If n is not an int, raise a TypeError with the exact message:
declare_temp_wires: only integers are accepted.
Note: Do not accept booleans (e.g., True/False) or other numeric types. Only plain int objects should be accepted.
Value validation
If n < 2, raise a ValueError with the exact message:
declare_temp_wires: cannot be less than 2.
Successful generation (n >= 2)
Return a string that exactly matches the formatting used in tests:
'\t// Declaring temporary wires\n\ttemp[{}:0];'.format(n - 1)
Example: for n = 2, return '\t// Declaring temporary wires\n\ttemp[1:0];'
Notes:
The string must include a leading tab on both lines and use a newline between lines, with no extra trailing whitespace.
Do not print anything; only return the string.
The tests import the function as:
from tree_stages_optional import declare_temp_wires
Design hints:
Use an exact type check (e.g., type(n) is int) to reject booleans and other non-plain-int values.
Keep the return format strictly as shown; string formatting can use .format() or an f-string, but the final result must match exactly.
Consider edge cases such as very large n to ensure the function handles large output efficiently, but no need for additional formatting or whitespace.
Acceptance criteria:
The function exists at the specified path and is importable.
It raises TypeError with the exact message for non-integer inputs (including booleans).
It raises ValueError with the exact message when n < 2.
It returns the exact string for valid inputs (n >= 2).