GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Clean up sqlite3.Connection APIs · Issue #108278 · python/cpython

Clean up sqlite3.Connection APIs #108278

New issue
Copy link
New issue
Copy link
Closed
Closed
Clean up sqlite3.Connection APIs#108278
Copy link
Labels
topic-sqlite3type-featureA feature request or enhancementA feature request or enhancement

Description

@erlend-aasland
erlend-aasland
opened on Aug 22, 2023
Issue body actions

Feature or enhancement

Has this already been discussed elsewhere?

https://discuss.python.org/t/clean-up-some-sqlite3-apis/32093

Links to previous discussion of this feature:

#87260 (comment)

Proposal:

The sqlite3.Connection class has groups of similar APIs with inconsistent parameter specs.

Create user-defined function APIs:

  • create_function(name, narg, func, *, deterministic=False)
  • create_aggregate(name, /, n_arg, aggregate_class)
  • create_window_function(name, num_params, aggregate_class, /)
  • create_collation(name, callable, /)

Set callback APIs:

  • set_authorizer(authorizer_callback)
  • set_progress_handler(progress_handler, n)
  • set_trace_callback(trace_callback)

For all APIs but create_function, I suggest to make all parameters positional-only; for create_function, I suggest to make the three first parameters positional-only:

Create user-defined function APIs:

  • create_function(name, nargs, callable, /, *, deterministic=False)
  • create_aggregate(name, nargs, aggregate_class, /)
  • create_window_function(name, nargs, aggregate_class, /)
  • create_collation(name, callable, /)

Set callback APIs:

  • set_authorizer(authorizer_callback, /)
  • set_progress_handler(progress_handler, /, n)
  • set_trace_callback(trace_callback, /)

Obviously, create_window_function stays as it is.

UPDATE: I noticed the docs are wrong about create_collation; it's signature is actually create_collation(name, callable, /).

Linked PRs

  • gh-108278: Deprecate passing the three first params as keyword args for sqlite3 UDF creation APIs #108281
  • gh-108278: Deprecate passing the first param of sqlite3.Connection callback APIs by keyword #108632

Activity

  1. erlend-aasland
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Aug 22, 2023
  2. erlend-aasland
    added this to sqlite3 issueson Aug 22, 2023
  3. erlend-aasland
    added
    topic-sqlite3
    on Aug 22, 2023
  4. erlend-aasland
    moved this to Backwards compatibility issues in sqlite3 issueson Aug 22, 2023
  5. erlend-aasland commented on Aug 22, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 22, 2023
    ContributorAuthor
    More actions

    cc. @serhiy-storchaka

  6. erlend-aasland
    added a commit that references this issue on Aug 22, 2023

    pythongh-108278: Clean up some sqlite3 connection APIs

    4f89b4c
  7. erlend-aasland
    changed the title [-]Clean up sqlite3 APIs[/-] [+]Clean up sqlite3.Connection APIs[/+] on Aug 22, 2023
  8. serhiy-storchaka commented on Aug 22, 2023

    @serhiy-storchaka
    serhiy-storchaka
    on Aug 22, 2023
    Member
    More actions

    Why keep n in set_progress_handler() as keyword-or-positional parameter? It is not very expressive name.

  9. erlend-aasland commented on Aug 22, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 22, 2023
    ContributorAuthor
    More actions

    Why keep n in set_progress_handler() as keyword-or-positional parameter? It is not very expressive name.

    I did consider it, and I'm still considering it :) I'm not sure what makes for the better API.

    1. con.set_progress_handler(func, 10)
    2. con.set_progress_handler(func, n=10)
  10. serhiy-storchaka commented on Aug 23, 2023

    @serhiy-storchaka
    serhiy-storchaka
    on Aug 23, 2023
    Member
    More actions

    Or maybe con.set_progress_handler(func, num_ops=10)? n may not be the best name.

    On other hand, set_progress_handler() has the order of parameters opposite to sqlite3_progress_handler(), it can cause confusion, so someone can call it as con.set_progress_handler(n=10, progress_handler=func).

    So I am not sure about these changes. On other hand, having different names narg, n_arg and num_params for virtually the same parameter is ridiculous. And name which can or cannot be passed by keyword. Ad func and callable which has virtually the same meaning in Python. So I agree with the first part of changes.

    Alternatively we can rename keyword arguments with keeping deprecated alias (#108271), but first we need to agree on names. It is easier to simply deprecate passing by keyword.

  11. erlend-aasland commented on Aug 23, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 23, 2023
    ContributorAuthor
    More actions

    Yes, it is easier to deprecate passing by keyword, and I also think it makes for a cleaner API.

    Regarding similarity to SQLite C API; I'm not sure it makes sense to align our APIs with those of SQLite. The sqlite3 extension module is a DB API implementation; it does not aim to be a Python shim over the SQLite C API (like apsw).

    I'll split my PR in two, so there is one PR for each API group; it will be easier to reason about.

  12. erlend-aasland commented on Aug 23, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 23, 2023
    ContributorAuthor
    More actions

    n may not be the best name.

    I agree; generally, I'm not a big fan of 1-letter variable/parameter names. num_ops or nops would be better. As you say, we'd need to resolve #108271 if we want to be able to rename a keyword parameter.

  13. erlend-aasland
    moved this from Backwards compatibility issues to In Progress in sqlite3 issueson Aug 23, 2023
  14. erlend-aasland
    added a commit that references this issue on Aug 28, 2023

    gh-108278: Deprecate passing the three first params as keyword args f…

    4116592
  15. vstinner
    added a commit that references this issue on Aug 28, 2023

    pythongh-108278: Deprecate passing the three first params as keyword …

    e4ede8e
  16. erlend-aasland
    added a commit that references this issue on Aug 29, 2023

    pythongh-108278: Deprecate passing the first param of sqlite3.Connect…

    a207531
  17. erlend-aasland commented on Aug 29, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 29, 2023
    ContributorAuthor
    More actions

    @serhiy-storchaka, I created a PR for the callback handlers. You raised a question regarding the n parameter of set_progress_handler, and also regarding the similarity to the SQLite C API.

    Regarding the latter, I already replied that I don't think the order of parameters in the SQLite C API should be directing the order of parameters in the sqlite3 API; the sqlite3 module is not apsw.

    Regarding my suggested omission of the n parameters in set_progress_handler, I am not sure what makes for the best API:

    1. set_progress_handler(func, n=100)
    2. set_progress_handler(func, 100)

    n is a single letter; one can argue that it does not convey a lot of meaning; n will probably be interpreted as meaning "count", but it is still unknown what is counted :) Obviously ninstr or num_instructions would have been a better choice. The easiest solution is to make it a positional parameter instead.

    Also, the docstring of set_progress_handler can be greatly improved, so perhaps n is fine, as long as the docstring explains it.

  18. erlend-aasland
    added a commit that references this issue on Aug 29, 2023

    gh-108278: Deprecate passing the first param of sqlite3.Connection ca…

    0b0c1d0
  19. erlend-aasland commented on Aug 29, 2023

    @erlend-aasland
    erlend-aasland
    on Aug 29, 2023
    ContributorAuthor
    More actions

    Thanks for your input and reviews, Serhiy.

  20. erlend-aasland
    closed this as completedon Aug 29, 2023
  21. github-project-automation
    moved this from In Progress to Done in sqlite3 issueson Aug 29, 2023
  22. carljm
    added a commit that references this issue on Aug 30, 2023

    Merge branch 'main' into icompexc

    37377e6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-sqlite3type-featureA feature request or enhancementA feature request or enhancement

    Projects

    • sqlite3 issues
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.