Skip to content

refactor: add generic type parameters for improved type flexibility #91

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tharropoulos
Copy link
Contributor

TLDR

Added generic type parameters to API key, override, and document schemas for better type flexibility.

Change Summary

Code Changes:

  1. In src/typesense/types/key.py:

    • Added _ActionT type variable with bounds for API key action type constraints
    • Made ApiKeyCreateSchema, ApiKeyCreateResponseSchema, ApiKeySchema, and ApiKeyRetrieveSchema generic with _ActionT parameter
    • Added backward compatibility aliases (ApiKeyCreateSchemaCompat, ApiKeySchemaCompat, etc.)
    • Replaced hardcoded _Actions union type with generic _ActionT parameter in actions field
  2. In src/typesense/types/override.py:

    • Added _OverrideRuleT type variable for override rule type constraints
    • Made OverrideCreateSchema and OverrideSchema generic with _OverrideRuleT parameter
    • Added compatibility type aliases (OverrideCreateSchemaCompat, OverrideSchemaCompat)
    • Replaced hardcoded union type with generic parameter in rule field
  3. In src/typesense/types/document.py:

    • Added _DocumentImportParamsT, _ImportResponseT, and _StringOrListT type variables
    • Added DocumentImportParametersGeneric type variable for document import parameters
    • Defined bounded type variables to improve type safety and flexibility
  4. In src/typesense/__init__.py:

    • Bumped version from 1.2.0 to 1.2.1

Context

#90

PR Checklist

- Add `_CreateFieldT` and `_UpdateFieldT` type variables for field type constraints
- Make `CollectionCreateSchema` generic with `_CreateFieldT` parameter
- Make `CollectionSchema` inherit generic parameter from `CollectionCreateSchema`
- Make `CollectionUpdateSchema` generic with `_UpdateFieldT` parameter
- Add `CollectionSchemaCompat` and `CollectionUpdateSchemaCompat` type aliases for backward compatibility
- Replace hardcoded union types with generic type parameters in field definitions
- Add `_DocumentImportParamsT` type variable for document import parameter constraints
- Add `_ImportResponseT` type variable for import response type constraints
- Add `_StringOrListT` type variable for string or list type constraints
- Add `DocumentImportParametersGeneric` type variable for document import parameters
- Define bounded type variables to improve type safety and flexibility
- Add `_ActionT` type variable for api key action type constraints
- Make `ApiKeyCreateSchema` generic with `_ActionT` parameter
- Make `ApiKeyCreateResponseSchema` inherit generic parameter from `ApiKeyCreateSchema`
- Make `ApiKeySchema` and `ApiKeyRetrieveSchema` generic with `_ActionT` parameter
- Add compatibility type aliases for backward compatibility
- Replace hardcoded `_Actions` union type with generic `_ActionT` parameter
- Add `_OverrideRuleT` type variable for override rule type constraints
- Make `OverrideCreateSchema` generic with `_OverrideRuleT` parameter
- Make `OverrideSchema` inherit generic parameter from `OverrideCreateSchema`
- Add `OverrideCreateSchemaCompat` and `OverrideSchemaCompat` type aliases for backward compatibility
- Replace hardcoded union type with generic `_OverrideRuleT` parameter in rule field
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.

1 participant