{"record":{"id":"f48aa27a1705f386","repo":"donnemartin/interactive-coding-challenges","slug":"data-cannot-be-none-f48aa2","errorCode":null,"errorMessage":"data cannot be None","messagePattern":"data cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"online_judges/busiest_period/busiest_period_solution.ipynb","lineNumber":168,"sourceCode":"    \"\\n\",\n    \"\\n\",\n    \"class EventType(Enum):\\n\",\n    \"\\n\",\n    \"    ENTER = 0\\n\",\n    \"    EXIT = 1\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 2,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"class Solution(object):\\n\",\n    \"\\n\",\n    \"    def find_busiest_period(self, data):\\n\",\n    \"        if data is None:\\n\",\n    \"            raise TypeError('data cannot be None')\\n\",\n    \"        if not data:\\n\",\n    \"            return None\\n\",\n    \"        data.sort()\\n\",\n    \"        max_period = Period(0, 0)\\n\",\n    \"        max_people = 0\\n\",\n    \"        curr_people = 0\\n\",\n    \"        for index, interval in enumerate(data):\\n\",\n    \"            if interval.event_type == EventType.ENTER:\\n\",\n    \"                curr_people += interval.num_people\\n\",\n    \"            elif interval.event_type == EventType.EXIT:\\n\",\n    \"                curr_people -= interval.num_people\\n\",\n    \"            else:\\n\",\n    \"                raise ValueError('Invalid event type')\\n\",\n    \"            if (index < len(data) - 1 and \\n\",\n    \"                    data[index].timestamp == data[index + 1].timestamp):\\n\",\n    \"                continue\\n\",\n    \"            if curr_people > max_people:\\n\",\n    \"                max_people = curr_people\\n\",","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/online_judges/busiest_period/busiest_period_solution.ipynb#L150-L186","documentation":"Raised by Solution.find_busiest_period when data is None. The method sorts and iterates the list of Interval records; None would fail at data.sort(), so it rejects None explicitly. (An empty list is legal and returns None.)","triggerScenarios":"Calling find_busiest_period(None) — e.g. a loader returned None on missing data, or a variable was initialized to None and never assigned before the call.","commonSituations":"Data pipelines where the events list comes from an optional source (empty file, failed fetch); tests covering the guard.","solutions":["Pass a list of Interval records","Fix the loader to return [] instead of None when there is no data","Guard: if data is not None: solution.find_busiest_period(data)"],"exampleFix":"# before\nrecords = load_events(path)  # returns None on missing file\nsolution.find_busiest_period(records)\n\n# after\nrecords = load_events(path) or []\nsolution.find_busiest_period(records)","handlingStrategy":"validation","validationCode":"if data is None: return None\nsolution.find_busiest_period(data)","typeGuard":"def is_interval_list(x): return isinstance(x, list) and all(hasattr(i, 'timestamp') for i in x)","tryCatchPattern":"try:\n    period = solution.find_busiest_period(data)\nexcept TypeError as e:\n    period = None\n    logger.warning(e)","preventionTips":["Make loaders return [] instead of None on empty","Check fetch results before analysis calls"],"tags":["python","input-validation","none-check","intervals","sorting"],"backgroundTag":"none-argument-validation","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}