Commit e770c5a
authored
Improve
## Problem
In v3.0, many methods have moved from the top-level namespace onto a
class instance. We can throw more informative errors to help people
migrate.
## Solution
Add back stub implementations of methods that were removed. When called,
they throw errors with useful documentation.
I simplified the expected args for all methods to `*args, **kwargs`
which should match no matter what combination of arguments the user has
provided.
## Type of Change
- [x] New feature (non-breaking change which adds functionality)
## Test Plan
`poetry run python3` and then try it:
```
poetry run python3
Python 3.9.16 (main, May 2 2023, 18:16:09)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pinecone
>>> pinecone.list_indexes()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jhamon/workspace/pinecone-python-client/pinecone/deprecation_warnings.py", line 21, in list_indexes
raise AttributeError(_build_class_migration_message('list_indexes', example))
AttributeError: list_indexes is no longer top-level attribute of the pinecone package.
To use list_indexes, please create a client instance and call the method there instead.
Example:
from pinecone import Pinecone
pc = Pinecone(api_key='YOUR_API_KEY')
index_name = "quickstart" # or your index name
if index_name not in pc.list_indexes().names():
# do something
>>> pinecone.create_index('quickstart', dimension=8, metric='cosine')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jhamon/workspace/pinecone-python-client/pinecone/deprecation_warnings.py", line 48, in create_index
raise AttributeError(_build_class_migration_message('create_index', example))
AttributeError: create_index is no longer top-level attribute of the pinecone package.
To use create_index, please create a client instance and call the method there instead.
Example:
from pinecone import Pinecone, ServerlessSpec
pc = Pinecone(api_key='YOUR_API_KEY')
pc.create_index(
name='my-index',
dimension=1536,
metric='euclidean',
spec=ServerlessSpec(
cloud='aws',
region='us-west-2'
)
)
>>> pinecone.describe_index('asdf')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jhamon/workspace/pinecone-python-client/pinecone/deprecation_warnings.py", line 30, in describe_index
raise AttributeError(_build_class_migration_message('describe_index', example))
AttributeError: describe_index is no longer top-level attribute of the pinecone package.
To use describe_index, please create a client instance and call the method there instead.
Example:
from pinecone import Pinecone
pc = Pinecone(api_key='YOUR_API_KEY')
pc.describe_index('my_index')
```
And `pinecone.init()`
```
>>> pinecone.init()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jhamon/workspace/pinecone-python-client/pinecone/deprecation_warnings.py", line 38, in init
raise AttributeError(msg)
AttributeError: init is no longer a top-level attribute of the pinecone package.
Please create an instance of the Pinecone class instead.
Example:
import os
from pinecone import Pinecone, ServerlessSpec
pc = Pinecone(
api_key=os.environ.get("PINECONE_API_KEY")
)
# Now do stuff
if 'my_index' not in pc.list_indexes().names():
pc.create_index(
name='my_index',
dimension=1536,
metric='euclidean',
spec=ServerlessSpec(
cloud='aws',
region='us-west-2'
)
)
```AttributeError warnings when using deprecated methods (#291)1 parent c84ea97 commit e770c5a
2 files changed
+152
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
0 commit comments