{"record":{"id":"0becb743b124c9b3","repo":"donnemartin/interactive-coding-challenges","slug":"invalid-argument-none","errorCode":null,"errorMessage":"Invalid argument: None","messagePattern":"Invalid argument: None","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"bit_manipulation/draw_line/draw_line_solution.ipynb","lineNumber":161,"sourceCode":"  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Code\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"class BitsScreen(object):\\n\",\n    \"\\n\",\n    \"    def draw_line(self, screen, width, x1, x2):\\n\",\n    \"        if None in (screen, width, x1, x2):\\n\",\n    \"            raise TypeError('Invalid argument: None')\\n\",\n    \"        if not screen or not width:\\n\",\n    \"            raise ValueError('Invalid arg: Empty screen or width')\\n\",\n    \"        MAX_BIT_VALUE = len(screen) * 8\\n\",\n    \"        if x1 < 0 or x2 < 0 or x1 >= MAX_BIT_VALUE or x2 >= MAX_BIT_VALUE:\\n\",\n    \"            raise ValueError('Invalid arg: x1 or x2 out of bounds')\\n\",\n    \"        start_bit = x1 % 8\\n\",\n    \"        end_bit = x2 % 8\\n\",\n    \"        first_full_byte = x1 // 8\\n\",\n    \"        if start_bit != 0:\\n\",\n    \"            first_full_byte += 1\\n\",\n    \"        last_full_byte = x2 // 8\\n\",\n    \"        if end_bit != (8 - 1):\\n\",\n    \"            last_full_byte -= 1\\n\",\n    \"        for byte in range(first_full_byte, last_full_byte + 1):\\n\",\n    \"            screen[byte] = int('11111111', base=2)\\n\",\n    \"        start_byte = x1 // 8\\n\",\n    \"        end_byte = x2 // 8\\n\",\n    \"        if start_byte == end_byte:\\n\",","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/bit_manipulation/draw_line/draw_line_solution.ipynb#L143-L179","documentation":"BitsScreen.draw_line raises TypeError('Invalid argument: None') when any of screen, width, x1, x2 is None. The routine performs arithmetic and indexing on all four parameters immediately, so it rejects None inputs before touching them.","triggerScenarios":"draw_line(None, 8, 0, 7), calling with a partially populated argument list, omitting a positional argument via a dict splat that misses keys, or passing optional params that defaulted to None.","commonSituations":"Screen buffers or dimensions loaded from config/payloads where fields are absent; refactoring a call site that dropped an argument.","solutions":["Pass all four arguments with concrete values: bytearray, width, x1, x2","Validate the payload/config that produces these values before calling","Use parameter defaults at the call site (e.g. x1 = x1 or 0) only when semantically safe"],"exampleFix":"# before\nbits.draw_line(screen, width, None, 10)\n\n# after\nif x1 is None:\n    x1 = 0\nbits.draw_line(screen, width, x1, 10)","handlingStrategy":"type-guard","validationCode":"if any(v is None for v in (screen, width, x1, x2)):\n    raise ValueError('screen, width, x1, x2 are all required')\nbits_screen.draw_line(screen, width, x1, x2)","typeGuard":"def has_all(*vals) -> bool:\n    return all(v is not None for v in vals)","tryCatchPattern":"try:\n    bits_screen.draw_line(screen, width, x1, x2)\nexcept TypeError as e:\n    if 'Invalid argument' in str(e):\n        raise ValueError('missing draw_line argument') from e\n    raise","preventionTips":["Build argument objects with required-key checks before splatting","Never let optional params default to None for drawing APIs","Assert preconditions in wrappers around low-level APIs"],"tags":["python","bit-manipulation","graphics","type-error","none-check"],"backgroundTag":"none-argument-type-error","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}