Migrate to Python 3.10+ Type Syntax #548
Merged
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.
Migrate to Python 3.10+ Type Syntax
Summary
This PR modernizes the Pinecone Python SDK's type annotations by migrating from legacy
typingmodule syntax to Python 3.10+ built-in type syntax. AllUnion[X, Y]usages are replaced withX | Y, allOptional[X]usages are replaced withX | None, and deprecated typing aliases (Dict,Tuple) are replaced with built-in types (dict,tuple).Problem
The SDK was using legacy type annotation syntax that has been superseded by cleaner, more readable Python 3.10+ syntax:
Union[X, Y]is verbose and less readable thanX | YOptional[X]is redundant whenX | Noneis more explicitDictandTuplefromtypingare deprecated in favor of built-indictandtuple(PEP 585)Since the SDK already requires Python 3.10+, we can take advantage of these modern syntax improvements.
Solution
Migrated all type annotations throughout the codebase to use Python 3.10+ syntax:
Union[X, Y]withX | YsyntaxOptional[X]withX | NonesyntaxDictwithdictandTuplewithtuplein non-generated codefrom __future__ import annotationswhere needed for forward referencesListfromtypingonly where necessary to avoid conflicts with methods namedlistUser-Facing Impact
Benefits
Breaking Changes
None - This is a purely syntactic change. All existing code continues to work without modification.
Migration Guide
No migration required for users. The changes are internal to the SDK and transparent to users.
Example Usage
The changes are internal, but here's how the improved type annotations look:
Before
After
Technical Details
Type Alias Handling
For type aliases that reference forward-declared types, we use
TypeAliaswith properTYPE_CHECKINGguards to ensure mypy can resolve types correctly while maintaining runtime compatibility.Naming Conflicts
In classes with methods named
list, we continue to useListfromtypingto avoid shadowing the built-in type. This affects:ApiKeyResource.list()methodIndexAsyncioInterface.list()method_IndexAsyncio.list()methodGRPCIndex.list()methodGenerated Code
Generated files in
pinecone/core/are not modified, as they are automatically generated from OpenAPI specifications. These will be updated when the code generation templates are updated in a future PR.Testing
Compatibility