{"record":{"id":"830211174a9a230d","repo":"donnemartin/interactive-coding-challenges","slug":"seq-cannot-be-none","errorCode":null,"errorMessage":"seq cannot be None","messagePattern":"seq cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"recursion_dynamic/longest_inc_subseq/longest_inc_subseq_solution.ipynb","lineNumber":115,"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 Subsequence(object):\\n\",\n    \"\\n\",\n    \"    def longest_inc_subseq(self, seq):\\n\",\n    \"        if seq is None:\\n\",\n    \"            raise TypeError('seq cannot be None')\\n\",\n    \"        if not seq:\\n\",\n    \"            return []\\n\",\n    \"        temp = [1] * len(seq)\\n\",\n    \"        prev = [None] * len(seq)\\n\",\n    \"        for r in range(1, len(seq)):\\n\",\n    \"            for l in range(r):\\n\",\n    \"                if seq[l] < seq[r]:\\n\",\n    \"                    if temp[r] < temp[l] + 1:\\n\",\n    \"                        temp[r] = temp[l] + 1\\n\",\n    \"                        prev[r] = l\\n\",\n    \"        max_val = 0\\n\",\n    \"        max_index = -1\\n\",\n    \"        results = []\\n\",\n    \"        for index, value in enumerate(temp):\\n\",\n    \"            if value > max_val:\\n\",\n    \"                max_val = value\\n\",\n    \"                max_index = index\\n\",\n    \"        curr_index = max_index\\n\",","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/recursion_dynamic/longest_inc_subseq/longest_inc_subseq_solution.ipynb#L97-L133","documentation":"Raised by Subsequence.longest_inc_subseq when seq is None. The function immediately allocates temp and prev arrays of length len(seq), so an explicit TypeError is thrown first with a descriptive message instead of the cryptic len(None) failure.","triggerScenarios":"Calling longest_inc_subseq(None). An empty sequence [] is handled and returns [] — only None raises.","commonSituations":"Passing a list built by a filter/map chain that can be None; sequence derived from an API response with a missing array field; optional parameters left as None.","solutions":["Default the argument: seq = seq or [] if an empty result is acceptable","Guard the call: if seq is not None: ... else handle empty case","Fix producers so pipelines return empty lists, never None"],"exampleFix":"// before\nresult = sub.longest_inc_subseq(maybe_none_seq)\n// after\nresult = sub.longest_inc_subseq(maybe_none_seq or [])","handlingStrategy":"validation","validationCode":"if seq is None:\n    seq = []\nsub.longest_inc_subseq(seq)","typeGuard":"def is_seq(x):\n    return isinstance(x, (list, tuple))","tryCatchPattern":"try:\n    sub.longest_inc_subseq(seq)\nexcept TypeError:\n    result = []","preventionTips":["Prefer empty lists over None as 'no data'","Check filter/map chain outputs"],"tags":["python","dynamic-programming","subsequence","input-validation"],"backgroundTag":"none-argument-validation","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}