{"record":{"id":"879f33b773abf1dc","repo":"donnemartin/interactive-coding-challenges","slug":"nums-cannot-be-none","errorCode":null,"errorMessage":"nums cannot be None","messagePattern":"nums cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"online_judges/move_zeroes/move_zeroes_solution.ipynb","lineNumber":135,"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 move_zeroes(self, nums):\\n\",\n    \"        if nums is None:\\n\",\n    \"            raise TypeError('nums cannot be None')\\n\",\n    \"        pos = 0\\n\",\n    \"        for num in nums:\\n\",\n    \"            if num != 0:\\n\",\n    \"                nums[pos] = num\\n\",\n    \"                pos += 1\\n\",\n    \"        if pos < len(nums):\\n\",\n    \"            nums[pos:] = [0] * (len(nums) - pos)\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Unit Test\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/online_judges/move_zeroes/move_zeroes_solution.ipynb#L117-L153","documentation":"Raised by Solution.move_zeroes when nums is None. The method rewrites nonzero elements in place over the front of the list and fills the tail with zeroes, so it needs a real list object. The guard converts an opaque 'NoneType has no len' failure into a clear message.","triggerScenarios":"Calling move_zeroes(None), or passing a value that is None because the source list failed to load.","commonSituations":"In-place array manipulation interview problem where the input comes from optional parsed data; forgetting a None default check before calling.","solutions":["Pass an empty list instead of None for 'no input'.","Check nums is not None at the call site before invoking.","If None is expected occasionally, wrap the call in try/except TypeError and skip."],"exampleFix":"# before\nSolution().move_zeroes(nums)  # nums is None\n\n# after\nif nums is not None:\n    Solution().move_zeroes(nums)","handlingStrategy":"type-guard","validationCode":"if nums is None:\n    nums = []\nSolution().move_zeroes(nums)","typeGuard":"def is_num_list(x):\n    return isinstance(x, list) and all(isinstance(n, (int, float)) for n in x)","tryCatchPattern":"try:\n    Solution().move_zeroes(nums)\nexcept TypeError as e:\n    if 'cannot be None' in str(e):\n        nums = []\n    else:\n        raise","preventionTips":["Default optional list parameters to [] (or None plus explicit normalization).","Check parsed inputs are non-None before in-place routines."],"tags":["python","null-check","in-place","typeerror"],"backgroundTag":"none-argument-guard","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}