Changed sqlalchemy adapter base model typing#85
Merged
HosseinNejatiJavaremi merged 1 commit intoSyntaxArc:masterfrom Oct 8, 2025
Merged
Changed sqlalchemy adapter base model typing#85HosseinNejatiJavaremi merged 1 commit intoSyntaxArc:masterfrom
HosseinNejatiJavaremi merged 1 commit intoSyntaxArc:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Improve SQLAlchemy Adapter Type Safety
Description
This PR improves type safety in the SQLAlchemy base adapter by replacing generic
BaseEntitytype annotations with the more specific generic type variableTthat is bound toBaseEntity. This change enhances type checking and provides better IDE support while maintaining backward compatibility.Changes Made
BaseEntitywithT(TypeVar bound to BaseEntity) in method signatures across both sync and async SQLAlchemy adaptersBaseSQLAlchemyAdapterandAsyncBaseSQLAlchemyAdapterto use the generic type variableTSpecific Method Updates
The following methods now use proper generic typing:
_apply_sorting()inSQLAlchemySortMixinexecute_search_query()in both sync and async adaptersdelete()andbulk_delete()methodstuple[list[T], int]Type of change
How Has This Been Tested?
The changes are purely type-related and maintain full backward compatibility. No runtime behavior is modified.
Checklist:
|unions)Additional context
This refactoring aligns with the project's commitment to modern Python 3.13 typing practices and follows the established patterns in the codebase. The use of
TypeVarbound toBaseEntityprovides:The changes maintain full compatibility with existing code while providing enhanced type safety for future development.
Technical Details
Before (using BaseEntity):
After (using generic T):
This change ensures that if you pass in
Useras the entity type, the return type will betuple[list[User], int]instead of the less specifictuple[list[BaseEntity], int].Files Modified
archipy/adapters/base/sqlalchemy/adapters.py- Updated type annotations for better type