Skip to content

Conversation

@max-muoto
Copy link
Contributor

@max-muoto max-muoto commented Dec 28, 2025

This PR resolves #12141 and improves the typing for create_aggregate by:

  • Splitting it out into two overloads, one for the n_arg=1 case that the protocol only accepts a single argument for step and inverse, and a separate protocol accepting N arguments when given a positive integer value or -1. Properties with Callable[..., object] are used in order to allow the implementer to accept any number of named positional or key-word arguments.
  • Adding corresponding protocols for create_window_function with the same pattern (_SingleParamWindowAggregateClass and _AnyParamWindowAggregateClass).
  • Adding test cases to verify both single-param and multi-param aggregate classes are accepted correctly.

This is primarily a re-open of #12192 addressing the issues called out in https://github.com/python/typeshed/pull/12192/changes#r1651411242. Looking back on this PR, the return-types were too strict as well, there's not necessarily a strict requirement that the return types match the input types so we avoid using generics for returns as well now.

@github-actions

This comment has been minimized.

@max-muoto max-muoto force-pushed the fix-aggregration-protocols branch from 6f5bc08 to ef3dc7d Compare December 30, 2025 01:24
# And for num_params = -1, which means the aggregate must accept any number of parameters.
@overload
def create_window_function(
self, name: str, num_params: Literal[-1], aggregate_class: Callable[[], _AnyParamWindowAggregateClass] | None, /
Copy link
Contributor Author

@max-muoto max-muoto Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't necessarily enforce usage of *args in the any params case.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@max-muoto max-muoto force-pushed the fix-aggregration-protocols branch from 199a193 to 8adf710 Compare December 30, 2025 01:59
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

incomplete type declaration at sqlite3.Connection.create_aggregate()

1 participant