{"record":{"id":"07b7311d631ea732","repo":"donnemartin/interactive-coding-challenges","slug":"a-or-b-cannot-be-none-07b731","errorCode":null,"errorMessage":"a or b cannot be None","messagePattern":"a or b cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"math_probability/sum_two/sum_two_solution.ipynb","lineNumber":122,"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 Solution(object):\\n\",\n    \"\\n\",\n    \"    def sum_two(self, a, b):\\n\",\n    \"        if a is None or b is None:\\n\",\n    \"            raise TypeError('a or b cannot be None')\\n\",\n    \"        result = a ^ b;\\n\",\n    \"        carry = (a&b) << 1\\n\",\n    \"        if carry != 0:\\n\",\n    \"            return self.sum_two(result, carry)\\n\",\n    \"        return result;\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Unit Test\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 2,\n   \"metadata\": {},","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/math_probability/sum_two/sum_two_solution.ipynb#L104-L140","documentation":"Raised by Solution.sum_two (bitwise addition via XOR/carry recursion) when either a or b is None. Both are required for a ^ b and (a & b) << 1; the guard gives a clear message instead of an obscure operand failure.","triggerScenarios":"Calling sum_two(None, 3) or sum_two(3, None) — commonly from partial argument passing, unpacking records with nulls, or forwarding defaults.","commonSituations":"Data-driven tests iterating (a, b) pairs that include None; adapters over nullable fields.","solutions":["Pass two integers","Validate both operands before the call","Sanitize input pairs, replacing or skipping nulls"],"exampleFix":"# before\nsolution.sum_two(a, b)  # b defaults to None\n\n# after\nb = 0 if b is None else b\nsolution.sum_two(a, b)","handlingStrategy":"validation","validationCode":"if a is None or b is None: raise ValueError('a and b are required')\nsolution.sum_two(a, b)","typeGuard":"def both_ints(*xs): return all(isinstance(x, int) for x in xs)","tryCatchPattern":"try:\n    solution.sum_two(a, b)\nexcept TypeError as e:\n    raise ValueError('invalid operands') from e","preventionTips":["Coalesce None operands to 0 when semantically safe","Validate pairs from external data before dispatch"],"tags":["python","input-validation","none-check","bit-manipulation","recursion"],"backgroundTag":"none-argument-validation","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}