Skip to content

Add typing overloads to Query.__getitem__ and AppenderQuery.__getitem__#13142

Closed
medovi40k wants to merge 6 commits intosqlalchemy:mainfrom
medovi40k:main
Closed

Add typing overloads to Query.__getitem__ and AppenderQuery.__getitem__#13142
medovi40k wants to merge 6 commits intosqlalchemy:mainfrom
medovi40k:main

Conversation

@medovi40k
Copy link
Copy Markdown
Contributor

@medovi40k medovi40k commented Feb 25, 2026

Fixes #13128

Description

Query.__getitem__ and AppenderQuery.__getitem__ previously returned Union[_T, List[_T]] for all inputs, making the return type inaccurate.
Added @overload signatures so that integer index returns _T and slice returns List[_T].

This pull request is:

  • A documentation / typographical / small typing error fix
    • Good to go, no issue or tests are needed

@zzzeek zzzeek requested a review from sqla-tester February 28, 2026 18:06
Copy link
Copy Markdown
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 zzzeek to try to get revision 5ae5675 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

New Gerrit review created for change 5ae5675: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6609

@zzzeek
Copy link
Copy Markdown
Member

zzzeek commented Feb 28, 2026

hey there -

can you try running:

nox -s pep484

and fix the failures occurring?

also for the pep8 fails (you can run these via nox -s pep8) you can install pre_commit which will run black / zimports and a quick flake8 upon next commit.

thanks!

@medovi40k
Copy link
Copy Markdown
Contributor Author

Heeyy!
I'm pretty new to that, so thank you for sharing some knowledge. I've solved the problems failing tests. All the tests (nox -s pep8 and nox -s pep484) returned succesful on my side! Could you review it one more time please?

@zzzeek zzzeek requested a review from sqla-tester February 28, 2026 23:10
Copy link
Copy Markdown
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 zzzeek to try to get revision 9ba1f01 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

Patchset 9ba1f01 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6609

@CaselIT CaselIT added this to the 2.0.x milestone Mar 18, 2026
@sqla-tester
Copy link
Copy Markdown
Collaborator

Federico Caselli (CaselIT) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6626

@sqlalchemy sqlalchemy deleted a comment from sqla-tester Mar 18, 2026
@sqla-tester
Copy link
Copy Markdown
Collaborator

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

@sqla-tester
Copy link
Copy Markdown
Collaborator

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

sqlalchemy-bot pushed a commit that referenced this pull request Mar 18, 2026
Fixes #13128

### Description
`Query.__getitem__` and `AppenderQuery.__getitem__` previously returned Union[_T, List[_T]] for all inputs, making the return type inaccurate.
Added `@overload` signatures so that integer index returns _T and slice returns List[_T].

This pull request is:

- [x] A documentation / typographical / small typing error fix
	- Good to go, no issue or tests are needed

Closes: #13142
Pull-request: #13142
Pull-request-sha: 9ba1f01

Change-Id: Ib37ab63d3d844491c34cc5ccfc4efc1591a1878c
(cherry picked from commit 8af25c2)
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.

AppenderQuery.__getitem__ should use typing.overload for more accurate return types

4 participants