Workspace/Coding labs
Loading progress

Resolve an actionable semantic target

Intermediate50 min

Implement resolve_target(tree, role, name) for an abstract UI tree. Each node has id, role, name, optional hidden/disabled booleans, and optional children. In this teaching model, hidden or disabled state on any ancestor excludes the entire subtree. Find the unique eligible exact role/name match, return its id, return None for no match, and raise ValueError for multiple matches. Trees are finite and acyclic. This inheritance model is intentionally simplified and does not claim full DOM or ARIA semantics.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

InputA visible region with one enabled Save button

OutputThe button id

The descendant is eligible.
EXAMPLE 2

InputA hidden region containing a visible Save button

OutputNone

Ancestor state excludes the subtree.
solution.pyPython 3.12