-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
bpo-40956: Convert sqlite3.connect and sqlite3.Connection.__init__ to AC #24421
Conversation
bd403c2
to
f70acce
Compare
FYI, rebased onto master. |
FYI, this is on my TODO list, but I want to take my time to review it since AC PRs tend to introduce regressions because of our lack of test coverage in this area. |
I can take a look at the code coverage later today. If it's possible to increase it by extending the unit test suite, we should do so first. |
I don't think we have a lot of tests for optional or keyword arguments of public APIs. #24503 is a recent example of a regression introduced due to lack of tests. |
Exactly. As far as I can see, all arguments are covered except EDIT: |
@berkerpeksag This will do the trick for diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py
index 39c9bf5b61..050094f895 100644
--- a/Lib/sqlite3/test/dbapi.py
+++ b/Lib/sqlite3/test/dbapi.py
@@ -533,6 +533,20 @@ def tearDown(self):
self.cur.close()
self.con.close()
+ def test_dont_check_same_thread(self):
+ def run(con, err):
+ try:
+ cur = con.execute("select 1")
+ except sqlite.Error:
+ err.append("multi-threading not allowed")
+
+ con = sqlite.connect(":memory:", check_same_thread=False)
+ err = []
+ t = threading.Thread(target=run, kwargs={"con": con, "err": err})
+ t.start()
+ t.join()
+ self.assertEqual(len(err), 0, "\n".join(err))
+
def test_con_cursor(self):
def run(con, errors):
try: BTW, |
@berkerpeksag Can I add tests for the UPDATE: Tests complementing keyword coverage has been added. |
This PR is stale because it has been open for 30 days with no activity. |
f70acce
to
a861358
Compare
Rebased onto |
detect_types: int = 0 | ||
isolation_level: object = NULL | ||
check_same_thread: bool(accept={int}) = True | ||
factory: object(c_default='(PyObject*)clinic_state()->ConnectionType') = ConnectionType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hummmm, i don't fully get how this is preserving the state as before. Seems that the previous code didn't have a default for factory and used NULL as the c default. Could you briefly explain how this default is preserving previous behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure :) This is the current code:
cpython/Modules/_sqlite/module.c
Lines 92 to 95 in 1d10bf0
if (factory == NULL) { | |
pysqlite_state *state = pysqlite_get_state(self); | |
factory = (PyObject *)state->ConnectionType; | |
} |
In practice, the factory
default is ConnectionType
, not NULL
, so I chose to let AC take care of this instead of writing it out explicitly in the function body. This also aligns well with the documentation, which says that factory
defaults to the sqlite3.Connection
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. Is other code using this branch in module.c:92
? I winder if we can enforce that a factory is always provided after this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is other code using this branch in module.c:92?
Not in the stdlib (except for some tests in the test suite), but I guess it's used in the wild. Personally, I would not have added this feature in the first place.
I winder if we can enforce that a factory is always provided after this PR
That's kind of what we're doing no with the default AC argument, right?
Not sure what's wrong with the "check generated files" CI; the last commit did not touch the clinic code in any way. I did a |
You are changing the AC and either there are some changes you did and you didn't regenerate or as subset of the files in the main branch has moved since then and therefore your files are not up to date. |
Commit af0fc7e passed the CI perfectly. All 98f1a9d did was adding two C comments (out of clinic scope). |
Let me know if you want further changes, @pablogsal. |
Great job @erlend-aasland! and thanks for the patience! 🚀 |
Many thanks, Pablo! |
…ctory (#95146) This PR partially reverts gh-24421 (PR) and fixes the remaining concerns given in gh-93044 (issue): - keyword arguments are passed as positional arguments to factory() - if an argument is not passed to sqlite3.connect(), its default value is passed to factory() Co-authored-by: Serhiy Storchaka <[email protected]>
…connect to factory (pythonGH-95146) This PR partially reverts pythongh-24421 (PR) and fixes the remaining concerns given in pythongh-93044 (issue): - keyword arguments are passed as positional arguments to factory() - if an argument is not passed to sqlite3.connect(), its default value is passed to factory() Co-authored-by: Serhiy Storchaka <[email protected]>. (cherry picked from commit a3d4d15) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
…t to factory (GH-95146) (#95158) This PR partially reverts gh-24421 (PR) and fixes the remaining concerns given in gh-93044 (issue): - keyword arguments are passed as positional arguments to factory() - if an argument is not passed to sqlite3.connect(), its default value is passed to factory() Co-authored-by: Serhiy Storchaka <[email protected]>. (cherry picked from commit a3d4d15) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
https://bugs.python.org/issue40956