Skip to content

bpo-31843: sqlite3.connect() now accepts PathLike objects as database name #4299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 7, 2017
Merged

bpo-31843: sqlite3.connect() now accepts PathLike objects as database name #4299

merged 8 commits into from
Nov 7, 2017

Conversation

Phaqui
Copy link
Contributor

@Phaqui Phaqui commented Nov 6, 2017

@@ -66,7 +66,7 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*

PyObject* result;

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|diOiOip", kwlist,
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|diOiOip", kwlist,
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why the function checks arguments.

Why not only relying on Connection constructor to check arguments?

Either remove the whole code to parse arguments, or fix the reference leak: Py_DECREF(database); is needed.

Copy link
Member

Choose a reason for hiding this comment

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

fix the reference leak: Py_DECREF(database); is needed.

Oops, it's not needed, you don't use PyUnicode_FSConverter, sorry. Your code is correct.

Copy link
Member

Choose a reason for hiding this comment

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

@Phaqui pointed me on IRC that the function contains a comment explaining that we have to parse all arguments to just extract the "factory" keyword argument... In that case, the code is ok.

*database* is a :term:`path-like object` giving the pathname (absolute or
relative to the current working directory) of the database file to be opened.
You can use ``":memory:"`` to open a database connection to a database that
resides in RAM instead of on disk.

Copy link
Member

Choose a reason for hiding this comment

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

You have to document the change. Something like:

.. versionchanged:: 3.7
   *database* can now also be a :term:`path-like object`, not only a string.

Copy link
Member

Choose a reason for hiding this comment

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

Done

``":memory:"`` to open a database connection to a database that resides in RAM
instead of on disk.
Opens a connection to the SQLite database file *database* and return a
:class:`Connection` object.
Copy link
Member

Choose a reason for hiding this comment

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

"return a Connection" is wrong, since it can be overridden by the factory parameter.

Either remove this addition, or rephrase it like: "Open a connection (...). By default, return a Connection object."

*database* is a :term:`path-like object` giving the pathname (absolute or
relative to the current working directory) of the database file to be opened.
You can use ``":memory:"`` to open a database connection to a database that
resides in RAM instead of on disk.

Copy link
Member

Choose a reason for hiding this comment

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

Done

is PathLike, i.e. has __fspath__(). """
self.addCleanup(unlink, TESTFN)
import pathlib
path = pathlib.Path(TESTFN)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that it's ok to depend on pathlib when testing sqlite.

I propose to replace it with:

class Path(os.PathLike):
    def __fspath__(self):
        return TESTFN

@vstinner
Copy link
Member

vstinner commented Nov 6, 2017

"bedevere/news — No news entry in Misc/NEWS.d/next/"

Can you please try to add one using the blurb tool?
https://devguide.python.org/committing/#what-s-new-and-news-entries

@Phaqui
Copy link
Contributor Author

Phaqui commented Nov 7, 2017

All review issues have now been corrected for.

@vstinner vstinner merged commit a22a127 into python:master Nov 7, 2017
embray pushed a commit to embray/cpython that referenced this pull request Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants