-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] Extract index request factory (#420)
## Problem With my asyncio client in progress (not in this diff), I found myself needing to reuse a lot of the openapi request-building boilerplate. ## Solution Rather than copy/paste and create a lot of duplication, I want to pull that logic out into a separate class for building request objects. This change should not break existing behavior in the Index client. ## Todo This was pretty much just a mechanical extraction. I'd like to cleanup and standardize some stuff regarding `_check_type`, an openapi param that we're going to silly lengths to flip the default behavior on, in a follow-up diff. ## Type of Change - [x] None of the above: Refactor ## Test Plan Should still have tests passing
- Loading branch information
Showing
6 changed files
with
248 additions
and
152 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class IndexClientInstantiationError(Exception): | ||
def __init__(self, index_args, index_kwargs): | ||
formatted_args = ", ".join(map(repr, index_args)) | ||
formatted_kwargs = ", ".join(f"{key}={repr(value)}" for key, value in index_kwargs.items()) | ||
combined_args = ", ".join([a for a in [formatted_args, formatted_kwargs] if a.strip()]) | ||
|
||
self.message = f"""You are attempting to access the Index client directly from the pinecone module. The Index client must be instantiated through the parent Pinecone client instance so that it can inherit shared configurations such as API key. | ||
INCORRECT USAGE: | ||
``` | ||
import pinecone | ||
pc = pinecone.Pinecone(api_key='your-api-key') | ||
index = pinecone.Index({combined_args}) | ||
``` | ||
CORRECT USAGE: | ||
``` | ||
from pinecone import Pinecone | ||
pc = Pinecone(api_key='your-api-key') | ||
index = pc.Index({combined_args}) | ||
``` | ||
""" | ||
super().__init__(self.message) | ||
|
||
|
||
class Index: | ||
def __init__(self, *args, **kwargs): | ||
raise IndexClientInstantiationError(args, kwargs) |
This file contains 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
Oops, something went wrong.