Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Type array_agg() #12461

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

Closed
wants to merge 1 commit into from
Closed

Type array_agg() #12461

wants to merge 1 commit into from

Conversation

dlax
Copy link
Contributor

@dlax dlax commented Mar 24, 2025

The return type of array_agg() is declared as a Sequence[T] where T is bound to the type of input argument.

This is implemented by making array_agg() inheriting from ReturnTypeFromArgs which provides appropriate overloads of __init__() to support this.

This usage of ReturnTypeFromArgs is a bit different from previous ones as the return type of the function is not exactly the same as that of its arguments, but a "collection" (a generic, namely a Sequence here) of the argument types. Accordingly, we adjust the code of tools/generate_sql_functions.py to retrieve the "collection" type from 'fn_class' annotation and generate expected return type.

Also add a couple of hand-written typing tests for PostgreSQL.

Related to #6810

The return type of array_agg() is declared as a `Sequence[T]` where `T`
is bound to the type of input argument.

This is implemented by making array_agg() inheriting from
ReturnTypeFromArgs which provides appropriate overloads of `__init__()`
to support this.

This usage of ReturnTypeFromArgs is a bit different from previous ones
as the return type of the function is not exactly the same as that of
its arguments, but a "collection" (a generic, namely a Sequence here) of
the argument types.  Accordingly, we adjust the code of
tools/generate_sql_functions.py to retrieve the "collection" type
from 'fn_class' annotation and generate expected return type
accordingly.

Also add a couple of hand-written typing tests for PostgreSQL.
@dlax dlax marked this pull request as ready for review March 24, 2025 17:07
Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

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

change looks ok, but I want to try cleaning up the overloads, since that type is used generically in all() for example

@CaselIT CaselIT requested a review from sqla-tester March 24, 2025 20:35
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision ba27cbb of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change ba27cbb: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5797

@CaselIT
Copy link
Member

CaselIT commented Mar 24, 2025

thanks!

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5797 has been merged. Congratulations! :)

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5798 has been merged. Congratulations! :)

sqlalchemy-bot pushed a commit that referenced this pull request Mar 27, 2025
The return type of `array_agg()` is declared as a `Sequence[T]` where `T` is bound to the type of input argument.

This is implemented by making `array_agg()` inheriting from `ReturnTypeFromArgs` which provides appropriate overloads of `__init__()` to support this.

This usage of ReturnTypeFromArgs is a bit different from previous ones as the return type of the function is not exactly the same as that of its arguments, but a "collection" (a generic, namely a Sequence here) of the argument types.  Accordingly, we adjust the code of `tools/generate_sql_functions.py` to retrieve the "collection" type from 'fn_class' annotation and generate expected return type.

Also add a couple of hand-written typing tests for PostgreSQL.

Related to #6810

Closes: #12461
Pull-request: #12461
Pull-request-sha: ba27cbb

Change-Id: I3fd538cc7092a0492c26970f0b825bf70ddb66cd
(cherry picked from commit 543acbd)
@dlax dlax deleted the typing-array_agg branch March 28, 2025 09:46
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.

3 participants