python / python/typeshed

incomplete type declaration at `sqlite3.Connection.create_aggregate()`

Open
#12,141 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stubs: false positive
Dominant language
Python
Stars
5.1k
Forks
2.1k
Avg merge
1d 19h
Merged PRs (30d)
82

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the sqlite3 dbapi2.pyi stub and compare create_aggregate with the documented sqlite3.Connection.create_aggregate behavior. Review _AnyParamWindowAggregateClass and _SqliteData in the same file, then determine the compatible declaration for multiple input values and non-integer aggregation results; done means the stub accurately accepts the documented use cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.