From 45738411668902b64242c2fcf012996120feac94 2023-08-28 12:01:15 From: Sergey B Kirpichev Date: 2023-08-28 12:01:15 Subject: [PATCH] Fix DeprecationWarning on 3.12 with a datetime adapter for sqlite3 After python/cpython#90016, default adapters and converters are deprecated. See also https://docs.python.org/3.12/library/sqlite3.html#sqlite3-adapter-converter-recipes --- diff --git a/IPython/core/history.py b/IPython/core/history.py index c81592a..7cf13a4 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -9,6 +9,7 @@ import datetime from pathlib import Path import re import sqlite3 +import sys import threading from traitlets.config.configurable import LoggingConfigurable @@ -29,6 +30,14 @@ from traitlets import ( observe, ) + +if sys.version_info >= (3, 12): + + def _adapt_datetime(val): + return val.isoformat(" ") + + sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + #----------------------------------------------------------------------------- # Classes and functions #-----------------------------------------------------------------------------