{"record":{"id":"42f79acb707a8510","repo":"python/cpython","slug":"nonetype-object-cannot-be-interpreted-as-an-inte","errorCode":null,"errorMessage":"'NoneType' object cannot be interpreted as an integer","messagePattern":"'NoneType' object cannot be interpreted as an integer","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Lib/_pydatetime.py","lineNumber":1029,"sourceCode":"            self = object.__new__(cls)\n            self.__setstate(year)\n            self._hashcode = -1\n            return self\n        year, month, day = _check_date_fields(year, month, day)\n        self = object.__new__(cls)\n        self._year = year\n        self._month = month\n        self._day = day\n        self._hashcode = -1\n        return self\n\n    # Additional constructors\n\n    @classmethod\n    def fromtimestamp(cls, t):\n        \"Construct a date from a POSIX timestamp (like time.time()).\"\n        if t is None:\n            raise TypeError(\"'NoneType' object cannot be interpreted as an integer\")\n        y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t)\n        return cls(y, m, d)\n\n    @classmethod\n    def today(cls):\n        \"Construct a date from time.time().\"\n        t = _time.time()\n        return cls.fromtimestamp(t)\n\n    @classmethod\n    def fromordinal(cls, n):\n        \"\"\"Construct a date from a proleptic Gregorian ordinal.\n\n        January 1 of year 1 is day 1.  Only the year, month and day are\n        non-zero in the result.\n        \"\"\"\n        y, m, d = _ord2ymd(n)\n        return cls(y, m, d)","sourceCodeStart":1011,"sourceCodeEnd":1047,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/_pydatetime.py#L1011-L1047","documentation":"Raised by date.fromtimestamp() when called with t=None. The pure-Python implementation guards explicitly against None before calling time.localtime(), because localtime(None) would otherwise behave inconsistently (in some builds None is treated as the current time, in others it errors). Passing None is treated as a programming error, not as 'now'.","triggerScenarios":"date.fromtimestamp(None); threading a value that defaults to None (e.g. date.fromtimestamp(os.environ.get('TS'))) into the API; calling fromtimestamp(row['ts']) where the column is NULL.","commonSituations":"Optional database timestamps that are NULL; function parameters defaulting to None then forwarded to fromtimestamp; migration from time.localtime(None)-tolerant code.","solutions":["Default to the current time explicitly: date.fromtimestamp(t if t is not None else time.time())","Handle NULL/None at the data boundary before calling fromtimestamp","Use date.today() when 'now' is the intent"],"exampleFix":"# before\nd = date.fromtimestamp(row['ts'])  # ts is None for NULL\n# after\nd = date.fromtimestamp(row['ts']) if row['ts'] is not None else date.today()","handlingStrategy":"validation","validationCode":"if t is None:\n    raise TypeError('timestamp required, got None')\nd = date.fromtimestamp(t)","typeGuard":"def valid_timestamp(t) -> bool:\n    return isinstance(t, (int, float))","tryCatchPattern":null,"preventionTips":["Handle NULL/None timestamps at the DB/IO boundary","Use date.today() when 'now' is intended — fromtimestamp(None) is not 'now'"],"tags":["datetime","typeerror","timestamp","null-handling"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}