Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Lib/sqlite3/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
import sqlite3
import sys

from argparse import ArgumentParser
from code import InteractiveConsole
from textwrap import dedent


def execute(c, sql, suppress_errors=True):
"""Helper that wraps execution of SQL code.
Expand All @@ -34,13 +30,15 @@ def execute(c, sql, suppress_errors=True):
sys.exit(1)


class SqliteInteractiveConsole(InteractiveConsole):
class SqliteInteractiveConsole:
Comment thread
Wulian233 marked this conversation as resolved.
Outdated
"""A simple SQLite REPL."""

def __init__(self, connection):
super().__init__()
from code import InteractiveConsole
self._con = connection
self._cur = connection.cursor()
self._console = InteractiveConsole()
self._console.runsource = self.runsource

def runsource(self, source, filename="<input>", symbol="single"):
"""Override runsource, the core of the InteractiveConsole REPL.
Expand All @@ -61,8 +59,14 @@ def runsource(self, source, filename="<input>", symbol="single"):
execute(self._cur, source)
return False

def interact(self, banner, exitmsg=""):
self._console.interact(banner, exitmsg=exitmsg)


def main(*args):
from argparse import ArgumentParser
from textwrap import dedent

Comment on lines 86 to +89
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see a valid reason to do code churn and delay imports for the sake of speeding up import sqlite3.__main__ while assuming that sqlite3.__main__.main() is never called.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume the following: execute is used by the REPL in addition to CLI; user code could import to use SQLiteInteractiveConsole. Whether worth it, not my call.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The REPL is of course part of calling main(), which makes my point quite well. :)

User code certainly could import SQLiteInteractiveConsole, as it lies within their technical capability. I think any user code importing an interactive console from a module named __main__ ought to be prepared to use it without worrying about the startup time of importing argparse and textwrap. A module called __main__ feels rather special to me in that sense -- one ought not casually resort to importing it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @eli-schwartz. This change looks meaningless.

parser = ArgumentParser(
description="Python sqlite3 CLI",
)
Expand Down
6 changes: 4 additions & 2 deletions Lib/sqlite3/dbapi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.

import time
import collections.abc
import datetime
import collections.abc

from _sqlite3 import *

Expand Down Expand Up @@ -54,7 +53,10 @@ def TimestampFromTicks(ticks):
Binary = memoryview
collections.abc.Sequence.register(Row)

# Lazy registe
def register_adapters_and_converters():
global _lazy_register
_lazy_register = lambda: None # Prevent multiple registration # noqa: E731
from warnings import warn

msg = ("The default {what} is deprecated as of Python 3.12; "
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Halve the import time of :mod:`sqlite3`.
Improve the import time of :mod:`sqlite3` by 1.5x faster.