From 45738411668902b64242c2fcf012996120feac94 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 18 Aug 2023 04:12:30 +0300 Subject: [PATCH 1/2] 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 --- IPython/core/history.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/IPython/core/history.py b/IPython/core/history.py index c81592a2c8f..7cf13a46e1a 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -9,6 +9,7 @@ from pathlib import Path import re import sqlite3 +import sys import threading from traitlets.config.configurable import LoggingConfigurable @@ -29,6 +30,14 @@ observe, ) + +if sys.version_info >= (3, 12): + + def _adapt_datetime(val): + return val.isoformat(" ") + + sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- From e1a3ce37f430f1c02b0afa4bacc90aa0d5eb1052 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 28 Aug 2023 11:57:57 +0200 Subject: [PATCH 2/2] Alternative stricter fix: explicit isoformat(" "), I think we need to avoid registering a default adapter, especially if CPython want to remove them. So we are going to call .isoformat(" ") explicitly. For backward compat we'll keep the delimiter as " ", but we might want to consider using the default of T later on, but still keeping in mind that old history have a space. --- IPython/core/history.py | 23 ++++++++++------------- IPython/core/logger.py | 1 - 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/IPython/core/history.py b/IPython/core/history.py index 7cf13a46e1a..fb67d158ef9 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -9,7 +9,6 @@ from pathlib import Path import re import sqlite3 -import sys import threading from traitlets.config.configurable import LoggingConfigurable @@ -30,14 +29,6 @@ observe, ) - -if sys.version_info >= (3, 12): - - def _adapt_datetime(val): - return val.isoformat(" ") - - sqlite3.register_adapter(datetime.datetime, _adapt_datetime) - #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- @@ -583,7 +574,7 @@ def new_session(self, conn=None): cur = conn.execute( """INSERT INTO sessions VALUES (NULL, ?, NULL, NULL, '') """, - (datetime.datetime.now(),), + (datetime.datetime.now().isoformat(" "),), ) self.session_number = cur.lastrowid @@ -591,9 +582,15 @@ def end_session(self): """Close the database session, filling in the end time and line count.""" self.writeout_cache() with self.db: - self.db.execute("""UPDATE sessions SET end=?, num_cmds=? WHERE - session==?""", (datetime.datetime.now(), - len(self.input_hist_parsed)-1, self.session_number)) + self.db.execute( + """UPDATE sessions SET end=?, num_cmds=? WHERE + session==?""", + ( + datetime.datetime.now().isoformat(" "), + len(self.input_hist_parsed) - 1, + self.session_number, + ), + ) self.session_number = 0 def name_session(self, name): diff --git a/IPython/core/logger.py b/IPython/core/logger.py index eeaba2429c4..ab12d10e229 100644 --- a/IPython/core/logger.py +++ b/IPython/core/logger.py @@ -20,7 +20,6 @@ import time - # prevent jedi/parso's debug messages pipe into interactiveshell logging.getLogger("parso").setLevel(logging.WARNING)