{"record":{"id":"fadb527a7606bc26","repo":"donnemartin/interactive-coding-challenges","slug":"sentence-cannot-be-none","errorCode":null,"errorMessage":"sentence cannot be None","messagePattern":"sentence cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"online_judges/sentence_screen_fit/sentence_screen_fit_solution.ipynb","lineNumber":163,"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 count_sentence_fit_brute_force(self, sentence, rows, cols):\\n\",\n    \"        if sentence is None:\\n\",\n    \"            raise TypeError('sentence cannot be None')\\n\",\n    \"        if rows is None or cols is None:\\n\",\n    \"            raise TypeError('rows and cols cannot be None')\\n\",\n    \"        if rows < 0 or cols < 0:\\n\",\n    \"            raise ValueError('rows and cols cannot be negative')\\n\",\n    \"        if cols == 0 or not sentence:\\n\",\n    \"            return 0\\n\",\n    \"        curr_row = 0\\n\",\n    \"        curr_col = 0\\n\",\n    \"        count = 0\\n\",\n    \"        while curr_row < cols:\\n\",\n    \"            for word in sentence:\\n\",\n    \"                # If the current word doesn't fit on the current line,\\n\",\n    \"                # move to the next line\\n\",\n    \"                if len(word) > cols - curr_col:\\n\",\n    \"                    curr_col = 0\\n\",\n    \"                    curr_row += 1\\n\",\n    \"                # If we are beyond the number of rows, return\\n\",\n    \"                if curr_row >= rows:\\n\",","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/online_judges/sentence_screen_fit/sentence_screen_fit_solution.ipynb#L145-L181","documentation":"This TypeError is raised by the brute-force sentence screen fit solver when the sentence argument is None. It is a deliberate input-validation guard at the top of count_sentence_fit_brute_force, before any algorithm logic runs, because joining/iterating a None sentence would otherwise fail with a less clear AttributeError. It signals the caller passed no sentence data to the API.","triggerScenarios":"Calling Solution().count_sentence_fit_brute_force(None, rows, cols) with any rows/cols values; e.g. passing a variable that was initialized to None or a lookup that returned None from a dict of test sentences.","commonSituations":"Test harnesses iterating over optional inputs where the sentence key is missing; refactoring code so the sentence list is conditionally built and stays None on the empty path; JSON/YAML config where the sentences field was omitted.","solutions":["Pass a valid list of sentence strings, e.g. ['hello', 'world']","Check the upstream variable that produces sentence and give it a default: sentence = sentence or []","Add a unit test asserting TypeError is raised for None to make the contract explicit"],"exampleFix":"// before\nsol.count_sentence_fit_brute_force(None, 5, 10)\n// after\nsol.count_sentence_fit_brute_force(['hello', 'world'], 5, 10)","handlingStrategy":"validation","validationCode":"if sentence is None:\n    raise ValueError('sentence input is required')\n# or: sentence = sentence or []\ncount = sol.count_sentence_fit_brute_force(sentence, rows, cols)","typeGuard":"def is_sentence_list(x):\n    return isinstance(x, list) and all(isinstance(w, str) for w in x)","tryCatchPattern":"try:\n    n = sol.count_sentence_fit_brute_force(sentence, rows, cols)\nexcept TypeError as e:\n    if 'sentence cannot be None' in str(e):\n        n = 0  # nothing to fit\n    else:\n        raise","preventionTips":["Initialize sentence collections to [] instead of None","Assert required inputs before calling solver methods","Cover the None contract in unit tests"],"tags":["python","input-validation","typeerror","algorithm"],"backgroundTag":"none-argument-typeerror","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}