Sqlite3: Could `None` be an alias for `":memory:"` database?

An in-memory database is created using sqlite3.connect(":memory:") with a string ":memory:" for database.

Since Python 3.7 sqlite3.connect supports os.PathLike for the database argument.

However if one uses pathlib.Path internally everywhere for dir/file manipulations, the ":memory:" string cannot be passed around, as Path(":memory:") does not fit into the pathlib.Path philosophy.

My question is, whether database=None could be used as an alias to ":memory:" to create an in-memory instance.

And how about making it default, so sqlite3.connect() without parameters creates an in-memory instance?

I feel having :memory: as default would be a tripmine for newcomers. Requiring an argument explicitly is more obvious.

What is the advantage to None over ":memory:"? None does not fit into pathlib.Path either. If it’s for type hinting, I actually feel Union[pathlib.Path, Literal[":memory:"]] more readable than Optional[pathlib.Path].

2 Likes