{"record":{"id":"5f9d71070a4f3b16","repo":"donnemartin/interactive-coding-challenges","slug":"array-cannot-be-none-5f9d71","errorCode":null,"errorMessage":"array cannot be None","messagePattern":"array cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sorting_searching/radix_sort/radix_sort_solution.ipynb","lineNumber":125,"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 RadixSort(object):\\n\",\n    \"\\n\",\n    \"    def sort(self, array, base=10):\\n\",\n    \"        if array is None:\\n\",\n    \"            raise TypeError('array cannot be None')\\n\",\n    \"        if not array:\\n\",\n    \"            return []\\n\",\n    \"        max_element = max(array)\\n\",\n    \"        max_digits = len(str(abs(max_element)))\\n\",\n    \"        curr_array = array\\n\",\n    \"        for digit in range(max_digits):\\n\",\n    \"            buckets = [[] for _ in range(base)]\\n\",\n    \"            for item in curr_array:\\n\",\n    \"                buckets[(item//(base**digit))%base].append(item)\\n\",\n    \"            curr_array = []\\n\",\n    \"            for bucket in buckets:\\n\",\n    \"                curr_array.extend(bucket)\\n\",\n    \"        return curr_array\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/sorting_searching/radix_sort/radix_sort_solution.ipynb#L107-L143","documentation":"RadixSort.sort raises TypeError('array cannot be None') when the array argument is None. Note the distinction: None raises TypeError, while an empty list is valid and returns []. This mirrors Python's sorted() contract of rejecting None.","triggerScenarios":"Calling RadixSort().sort(None); passing a variable that was never assigned or whose source (file parse, query result) returned None.","commonSituations":"Data ingestion steps that can return None on failure; refactors making the array parameter optional; interactive/notebook sessions with stale or unset variables.","solutions":["Ensure the input is a list; substitute [] for None if the empty case is intended","Check where the array comes from and handle the None-producing failure there","Add an assertion or early return in the caller for None inputs"],"exampleFix":"// before\nresult = RadixSort().sort(array)  # array may be None\n\n// after\nresult = RadixSort().sort(array if array is not None else [])","handlingStrategy":"validation","validationCode":"if array is None:\n    array = []\nresult = RadixSort().sort(array)","typeGuard":"def is_sortable(x):\n    return isinstance(x, list)","tryCatchPattern":"try:\n    result = rs.sort(array)\nexcept TypeError as e:\n    if 'cannot be None' in str(e):\n        result = []\n    else:\n        raise","preventionTips":["Treat None and [] consistently in your data layer","Check parsed numeric inputs exist before sorting","Add early assertions for required list arguments"],"tags":["python","input-validation","typeerror","radix-sort"],"backgroundTag":"none-input-validation","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}