Exercise 2: A Genuinely Empty Declaration Block — Possible Solution ==================================================================== THE TEST ------------------------------ parse_css("p {}") RESULT ------------------------------ No error raised. Rule.selectors == ['p'] Rule.declarations == [] WHY THIS DOESN'T ERROR ------------------------------ parse_css finds the '{' and the matching '}' exactly as it would for any rule -- decl_text ends up as the empty string '' (there are zero characters between the braces). That empty string is handed to parse_declarations, which runs: for chunk in block.split(';'): chunk = chunk.strip() if not chunk or ':' not in chunk: continue ... ''.split(';') returns [''] -- a list containing one single empty string, not an empty list. The loop body still runs once, chunk becomes '' after stripping, and the very first condition, `if not chunk`, is true for an empty string -- so that one iteration is simply skipped via `continue`, and the function falls through to its own final `return declarations`, which is still the empty list it started with. WHY THIS WORKS AS AN ANSWER ------------------------------ The specific check responsible is `if not chunk or ':' not in chunk: continue` -- the `not chunk` half of that condition is what catches the empty-block case (the `':' not in chunk` half is what protects against a different kind of malformed input, a chunk with no colon at all). Nothing about parse_declarations assumes a block contains at least one real declaration; an empty block is treated exactly the same way a block containing only whitespace or a stray trailing semicolon would be -- as zero declarations, silently, with no special case written specifically for "the block was completely empty."