Skip to content
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

[sqlite3] consider adding Py_TPFLAGS_DISALLOW_INSTANTIATION to sqlite3.Statement #88253

Closed
erlend-aasland opened this issue May 9, 2021 · 3 comments
Labels
easy type-feature A feature request or enhancement

Comments

@erlend-aasland
Copy link
Contributor

BPO 44087
Nosy @berkerpeksag, @serhiy-storchaka, @pablogsal, @miss-islington, @erlend-aasland
PRs
  • bpo-44087: Disallow instantiation of sqlite3.Statement #26567
  • [3.10] bpo-44087: Disallow instantiation of sqlite3.Statement (GH-26567) #26813
  • [3.10] bpo-44087: Disallow instantiation of sqlite3.Statement (GH-26567) #26816
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-06-20.21:29:55.005>
    created_at = <Date 2021-05-09.08:28:09.445>
    labels = ['easy', 'type-feature']
    title = '[sqlite3] consider adding Py_TPFLAGS_DISALLOW_INSTANTIATION to sqlite3.Statement'
    updated_at = <Date 2021-06-20.21:29:55.005>
    user = 'https://github.com/erlend-aasland'

    bugs.python.org fields:

    activity = <Date 2021-06-20.21:29:55.005>
    actor = 'erlendaasland'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-06-20.21:29:55.005>
    closer = 'erlendaasland'
    components = []
    creation = <Date 2021-05-09.08:28:09.445>
    creator = 'erlendaasland'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44087
    keywords = ['patch', 'easy (C)']
    message_count = 3.0
    messages = ['393310', '396189', '396201']
    nosy_count = 5.0
    nosy_names = ['berker.peksag', 'serhiy.storchaka', 'pablogsal', 'miss-islington', 'erlendaasland']
    pr_nums = ['26567', '26813', '26816']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue44087'
    versions = []

    @erlend-aasland
    Copy link
    Contributor Author

    Currently, the sqlite3.Statement type is not exposed in the module dict:

    >>> import sqlite3
    >>> sqlite3.Statement
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/sqlite3/__init__.py", line 37, in __getattr__
        raise AttributeError(f"module 'sqlite3' has no attribute '{name}'")
    AttributeError: module 'sqlite3' has no attribute 'Statement'
    
    
    It is possible to extract it using this trick:
    >>> cx = sqlite3.connect(":memory:")
    >>> stmt = cx("select 1")
    >>> type(stmt)
    <class 'sqlite3.Statement'>
    >>> type(stmt)()
    <sqlite3.Statement object at 0x109006b30>

    There is no use case for this; statement objects belong to the internal workings of the sqlite3 module. I suggest adding Py_TPFLAGS_DISALLOW_INSTANTIATION to make this fact more explicit.

    @erlend-aasland erlend-aasland added easy type-feature A feature request or enhancement labels May 9, 2021
    @pablogsal
    Copy link
    Member

    New changeset 7d0a47e by Erlend Egeberg Aasland in branch 'main':
    bpo-44087: Disallow instantiation of sqlite3.Statement (GH-26567)
    7d0a47e

    @pablogsal
    Copy link
    Member

    New changeset ccc95c7 by Erlend Egeberg Aasland in branch '3.10':
    [3.10] bpo-44087: Disallow instantiation of sqlite3.Statement (GH-26567) (GH-26816)
    ccc95c7

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants