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

incomplete type declaration at sqlite3.Connection.create_aggregate() #12141

Open
kunom opened this issue Jun 16, 2024 · 3 comments
Open

incomplete type declaration at sqlite3.Connection.create_aggregate() #12141

kunom opened this issue Jun 16, 2024 · 3 comments
Labels
stubs: false positive Type checkers report false errors

Comments

@kunom
Copy link

kunom commented Jun 16, 2024

Bug report

Bug description:

The create_aggregate documentation does not specify a result type of the aggregation and even allows for multiple aggregating values per row (n_arg parameter).

However, the type declaration at dbapi2.pyi does not reflect that (comments added by me):

def create_aggregate(self, name: str, n_arg: int, aggregate_class: Callable[[], _AggregateProtocol]) -> None: ...

class _AggregateProtocol(Protocol):
    def step(self, value: int, /) -> object: ...  # <-- just one aggregating value of type int
    def finalize(self) -> int: ...   # <-- result has to be int

I think that this is not correct. At least, I have working code that aggregates multiple strings into a combined one.

Also, it is in stark contrast to other, way more generic, type declarations at the same place (comments added by me):

class _AnyParamWindowAggregateClass(Protocol):
    def step(self, *args: Any) -> object: ... # <-- multiple aggregating values of any type allowed
    def inverse(self, *args: Any) -> object: ...
    def value(self) -> _SqliteData: ...
    def finalize(self) -> _SqliteData: ... # <-- result can be many more types

_SqliteData: TypeAlias = str | ReadableBuffer | int | float | None

CPython versions tested on:

3.12

Operating systems tested on:

Windows

@Eclips4
Copy link
Member

Eclips4 commented Jun 16, 2024

Hello!
This repository is intended as a CPython bug tracker, your problem is actually related to stubs which is not part of CPython; It's a part of typeshed.
I can't transfer this issue to the typeshed repo, @AlexWaygood maybe you can? 🙂

@sobolevn sobolevn transferred this issue from python/cpython Jun 16, 2024
@sobolevn
Copy link
Member

This is indeed a typeshed problem. CPython documents that finalize() returns:

finalize(): Return the final result of the aggregate as a type natively supported by SQLite.

Looks like this protocol should be generic.

@kunom
Copy link
Author

kunom commented Jun 16, 2024

Just to summarize my request:

  • step can take multiple arguments of several types
  • finalize can return several types

@srittau srittau added the stubs: false positive Type checkers report false errors label Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

No branches or pull requests

4 participants