{"record":{"id":"98de2a5dc8aa36d9","repo":"donnemartin/interactive-coding-challenges","slug":"array-cannot-be-none-98de2a","errorCode":null,"errorMessage":"array cannot be None","messagePattern":"array cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"online_judges/mult_other_numbers/mult_other_numbers_solution.ipynb","lineNumber":140,"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 mult_other_numbers_brute(self, array):\\n\",\n    \"        if array is None:\\n\",\n    \"            raise TypeError('array cannot be None')\\n\",\n    \"        if not array:\\n\",\n    \"            return array\\n\",\n    \"        if len(array) == 1:\\n\",\n    \"            return []\\n\",\n    \"        result = []\\n\",\n    \"        for i in range(len(array)):\\n\",\n    \"            curr_sum = 1\\n\",\n    \"            for j in range(len(array)):\\n\",\n    \"                if i == j:\\n\",\n    \"                    continue\\n\",\n    \"                curr_sum *= array[j]\\n\",\n    \"            result.append(curr_sum)\\n\",\n    \"        return result\\n\",\n    \"\\n\",\n    \"    def mult_other_numbers(self, array):\\n\",\n    \"        if array is None:\\n\",\n    \"            raise TypeError('array cannot be None')\\n\",\n    \"        if not array:\\n\",","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/online_judges/mult_other_numbers/mult_other_numbers_solution.ipynb#L122-L158","documentation":"Raised by the brute-force variant Solution.mult_other_numbers_brute when array is None. It builds, for each index, the product of every other element; a None input cannot be iterated, so the method fails fast with TypeError('array cannot be None').","triggerScenarios":"Calling mult_other_numbers_brute(None), or sharing one optional input variable between the brute and optimized variants without null-checking.","commonSituations":"Benchmarking both implementations with the same dataset loader that can return None on parse failure.","solutions":["Coalesce to a list: mult_other_numbers_brute(array or []).","Fix the loader so it returns [] on empty/failed input instead of None.","Catch TypeError around the call for defensive top-level handling."],"exampleFix":"# before\nresult = Solution().mult_other_numbers_brute(data)  # data may be None\n\n# after\nresult = Solution().mult_other_numbers_brute(data or [])","handlingStrategy":"type-guard","validationCode":"array = array or []\nresult = Solution().mult_other_numbers_brute(array)","typeGuard":"def is_int_list(x):\n    return isinstance(x, list) and all(isinstance(v, int) for v in x)","tryCatchPattern":"try:\n    Solution().mult_other_numbers_brute(array)\nexcept TypeError as e:\n    if 'cannot be None' in str(e):\n        array = []\n    else:\n        raise","preventionTips":["Normalize loader output: return [] not None on empty/failed parse.","Share one normalization helper across brute and optimized variants."],"tags":["python","null-check","brute-force","typeerror"],"backgroundTag":"none-argument-guard","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}