Skip to content

Commit 453d7cb

Browse files
author
Daniel Melo
committed
use Mapping instead of Dict, Sequence instead of List
1 parent 921e0b4 commit 453d7cb

File tree

3 files changed

+47
-47
lines changed

3 files changed

+47
-47
lines changed

Diff for: pinecone/core/client/api_client.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,16 @@ def __call_api(
118118
self,
119119
resource_path: str,
120120
method: str,
121-
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
122-
query_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
123-
header_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
121+
path_params: typing.Optional[typing.Mapping[str, typing.Any]] = None,
122+
query_params: typing.Optional[typing.Sequence[typing.Tuple[str, typing.Any]]] = None,
123+
header_params: typing.Optional[typing.Mapping[str, typing.Any]] = None,
124124
body: typing.Optional[typing.Any] = None,
125-
post_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
126-
files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None,
125+
post_params: typing.Optional[typing.Sequence[typing.Tuple[str, typing.Any]]] = None,
126+
files: typing.Optional[typing.Mapping[str, typing.Sequence[io.IOBase]]] = None,
127127
response_type: typing.Optional[typing.Tuple[typing.Any]] = None,
128-
auth_settings: typing.Optional[typing.List[str]] = None,
128+
auth_settings: typing.Optional[typing.Sequence[str]] = None,
129129
_return_http_data_only: typing.Optional[bool] = None,
130-
collection_formats: typing.Optional[typing.Dict[str, str]] = None,
130+
collection_formats: typing.Optional[typing.Mapping[str, str]] = None,
131131
_preload_content: bool = True,
132132
_request_timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
133133
_host: typing.Optional[str] = None,
@@ -280,9 +280,9 @@ def sanitize_for_serialization(cls, obj):
280280
return obj.isoformat()
281281
elif isinstance(obj, ModelSimple):
282282
return cls.sanitize_for_serialization(obj.value)
283-
elif isinstance(obj, (list, tuple)):
283+
elif isinstance(obj, typing.Sequence):
284284
return [cls.sanitize_for_serialization(item) for item in obj]
285-
if isinstance(obj, dict):
285+
if isinstance(obj, typing.Mapping):
286286
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
287287
raise PineconeApiValueError('Unable to prepare type {} for serialization'.format(obj.__class__.__name__))
288288

@@ -335,17 +335,17 @@ def call_api(
335335
self,
336336
resource_path: str,
337337
method: str,
338-
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
339-
query_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
340-
header_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
338+
path_params: typing.Optional[typing.Mapping[str, typing.Any]] = None,
339+
query_params: typing.Optional[typing.Sequence[typing.Tuple[str, typing.Any]]] = None,
340+
header_params: typing.Optional[typing.Mapping[str, typing.Any]] = None,
341341
body: typing.Optional[typing.Any] = None,
342-
post_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
343-
files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None,
342+
post_params: typing.Optional[typing.Sequence[typing.Tuple[str, typing.Any]]] = None,
343+
files: typing.Optional[typing.Mapping[str, typing.Sequence[io.IOBase]]] = None,
344344
response_type: typing.Optional[typing.Tuple[typing.Any]] = None,
345-
auth_settings: typing.Optional[typing.List[str]] = None,
345+
auth_settings: typing.Optional[typing.Sequence[str]] = None,
346346
async_req: typing.Optional[bool] = None,
347347
_return_http_data_only: typing.Optional[bool] = None,
348-
collection_formats: typing.Optional[typing.Dict[str, str]] = None,
348+
collection_formats: typing.Optional[typing.Mapping[str, str]] = None,
349349
_preload_content: bool = True,
350350
_request_timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
351351
_host: typing.Optional[str] = None,
@@ -497,7 +497,7 @@ def parameters_to_tuples(self, params, collection_formats):
497497
new_params = []
498498
if collection_formats is None:
499499
collection_formats = {}
500-
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
500+
for k, v in params.items() if isinstance(params, typing.Mapping) else params: # noqa: E501
501501
if k in collection_formats:
502502
collection_format = collection_formats[k]
503503
if collection_format == 'multi':
@@ -523,7 +523,7 @@ def get_file_data_and_close_file(file_instance: io.IOBase) -> bytes:
523523
file_instance.close()
524524
return file_data
525525

526-
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
526+
def files_parameters(self, files: typing.Optional[typing.Mapping[str, typing.Sequence[io.IOBase]]] = None):
527527
"""Builds form parameters.
528528
529529
:param files: None or a dict with key=param_name and

Diff for: pinecone/data/index.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from tqdm.autonotebook import tqdm
22

33
from collections.abc import Iterable
4-
from typing import Union, List, Tuple, Optional, Dict, Any
4+
from typing import Mapping, Union, List, Tuple, Optional, Dict, Any
55

66
from pinecone.config import ConfigBuilder
77

@@ -74,12 +74,12 @@ def __init__(
7474
api_key: str,
7575
host: str,
7676
pool_threads: Optional[int] = 1,
77-
additional_headers: Optional[Dict[str, str]] = {},
77+
additional_headers: Optional[Mapping[str, str]] = {},
7878
**kwargs
7979
):
8080
self._config = ConfigBuilder.build(api_key=api_key, host=host, **kwargs)
81-
82-
api_client = ApiClient(configuration=self._config.openapi_config,
81+
82+
api_client = ApiClient(configuration=self._config.openapi_config,
8383
pool_threads=pool_threads)
8484

8585
# Configure request headers
@@ -90,7 +90,7 @@ def __init__(
9090

9191
self._api_client = api_client
9292
self._vector_api = VectorOperationsApi(api_client=api_client)
93-
93+
9494
def __enter__(self):
9595
return self
9696

@@ -245,7 +245,7 @@ def delete(
245245
ids: Optional[List[str]] = None,
246246
delete_all: Optional[bool] = None,
247247
namespace: Optional[str] = None,
248-
filter: Optional[Dict[str, Union[str, float, int, bool, List, dict]]] = None,
248+
filter: Optional[Mapping[str, Union[str, float, int, bool, List, dict]]] = None,
249249
**kwargs,
250250
) -> Dict[str, Any]:
251251
"""
@@ -272,7 +272,7 @@ def delete(
272272
Default is False.
273273
namespace (str): The namespace to delete vectors from [optional]
274274
If not specified, the default namespace is used.
275-
filter (Dict[str, Union[str, float, int, bool, List, dict]]):
275+
filter (Mapping[str, Union[str, float, int, bool, List, dict]]):
276276
If specified, the metadata filter here will be used to select the vectors to delete.
277277
This is mutually exclusive with specifying ids to delete in the ids param or using delete_all=True.
278278
See https://www.pinecone.io/docs/metadata-filtering/.. [optional]
@@ -330,10 +330,10 @@ def query(
330330
vector: Optional[List[float]] = None,
331331
id: Optional[str] = None,
332332
namespace: Optional[str] = None,
333-
filter: Optional[Dict[str, Union[str, float, int, bool, List, dict]]] = None,
333+
filter: Optional[Mapping[str, Union[str, float, int, bool, List, dict]]] = None,
334334
include_values: Optional[bool] = None,
335335
include_metadata: Optional[bool] = None,
336-
sparse_vector: Optional[Union[SparseValues, Dict[str, Union[List[float], List[int]]]]] = None,
336+
sparse_vector: Optional[Union[SparseValues, Mapping[str, Union[List[float], List[int]]]]] = None,
337337
**kwargs,
338338
) -> QueryResponse:
339339
"""
@@ -362,17 +362,17 @@ def query(
362362
top_k (int): The number of results to return for each query. Must be an integer greater than 1.
363363
namespace (str): The namespace to fetch vectors from.
364364
If not specified, the default namespace is used. [optional]
365-
filter (Dict[str, Union[str, float, int, bool, List, dict]):
365+
filter (Mapping[str, Union[str, float, int, bool, List, dict]):
366366
The filter to apply. You can use vector metadata to limit your search.
367367
See https://www.pinecone.io/docs/metadata-filtering/.. [optional]
368368
include_values (bool): Indicates whether vector values are included in the response.
369369
If omitted the server will use the default value of False [optional]
370370
include_metadata (bool): Indicates whether metadata is included in the response as well as the ids.
371371
If omitted the server will use the default value of False [optional]
372-
sparse_vector: (Union[SparseValues, Dict[str, Union[List[float], List[int]]]]): sparse values of the query vector.
372+
sparse_vector: (Union[SparseValues, Mapping[str, Union[List[float], List[int]]]]): sparse values of the query vector.
373373
Expected to be either a SparseValues object or a dict of the form:
374374
{'indices': List[int], 'values': List[float]}, where the lists each have the same length.
375-
375+
376376
Returns: QueryResponse object which contains the list of the closest vectors as ScoredVector objects,
377377
and namespace name.
378378
"""
@@ -414,9 +414,9 @@ def update(
414414
self,
415415
id: str,
416416
values: Optional[List[float]] = None,
417-
set_metadata: Optional[Dict[str, Union[str, float, int, bool, List[int], List[float], List[str]]]] = None,
417+
set_metadata: Optional[Mapping[str, Union[str, float, int, bool, List[int], List[float], List[str]]]] = None,
418418
namespace: Optional[str] = None,
419-
sparse_values: Optional[Union[SparseValues, Dict[str, Union[List[float], List[int]]]]] = None,
419+
sparse_values: Optional[Union[SparseValues, Mapping[str, Union[List[float], List[int]]]]] = None,
420420
**kwargs,
421421
) -> Dict[str, Any]:
422422
"""
@@ -438,10 +438,10 @@ def update(
438438
Args:
439439
id (str): Vector's unique id.
440440
values (List[float]): vector values to set. [optional]
441-
set_metadata (Dict[str, Union[str, float, int, bool, List[int], List[float], List[str]]]]):
441+
set_metadata (Mapping[str, Union[str, float, int, bool, List[int], List[float], List[str]]]]):
442442
metadata to set for vector. [optional]
443443
namespace (str): Namespace name where to update the vector.. [optional]
444-
sparse_values: (Dict[str, Union[List[float], List[int]]]): sparse values to update for the vector.
444+
sparse_values: (Mapping[str, Union[List[float], List[int]]]): sparse values to update for the vector.
445445
Expected to be either a SparseValues object or a dict of the form:
446446
{'indices': List[int], 'values': List[float]} where the lists each have the same length.
447447
@@ -472,7 +472,7 @@ def update(
472472

473473
@validate_and_convert_errors
474474
def describe_index_stats(
475-
self, filter: Optional[Dict[str, Union[str, float, int, bool, List, dict]]] = None, **kwargs
475+
self, filter: Optional[Mapping[str, Union[str, float, int, bool, List, dict]]] = None, **kwargs
476476
) -> DescribeIndexStatsResponse:
477477
"""
478478
The DescribeIndexStats operation returns statistics about the index's contents.
@@ -485,7 +485,7 @@ def describe_index_stats(
485485
>>> index.describe_index_stats(filter={'key': 'value'})
486486
487487
Args:
488-
filter (Dict[str, Union[str, float, int, bool, List, dict]]):
488+
filter (Mapping[str, Union[str, float, int, bool, List, dict]]):
489489
If this parameter is present, the operation only returns statistics for vectors that satisfy the filter.
490490
See https://www.pinecone.io/docs/metadata-filtering/.. [optional]
491491
@@ -509,15 +509,15 @@ def _parse_non_empty_args(args: List[Tuple[str, Any]]) -> Dict[str, Any]:
509509

510510
@staticmethod
511511
def _parse_sparse_values_arg(
512-
sparse_values: Optional[Union[SparseValues, Dict[str, Union[List[float], List[int]]]]]
512+
sparse_values: Optional[Union[SparseValues, Mapping[str, Union[List[float], List[int]]]]]
513513
) -> Optional[SparseValues]:
514514
if sparse_values is None:
515515
return None
516516

517517
if isinstance(sparse_values, SparseValues):
518518
return sparse_values
519519

520-
if not isinstance(sparse_values, dict) or "indices" not in sparse_values or "values" not in sparse_values:
520+
if not isinstance(sparse_values, Mapping) or "indices" not in sparse_values or "values" not in sparse_values:
521521
raise ValueError(
522522
"Invalid sparse values argument. Expected a dict of: {'indices': List[int], 'values': List[float]}."
523523
f"Received: {sparse_values}"

Diff for: pinecone/grpc/index_grpc.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Optional, Dict, Union, List, Tuple, Any, TypedDict, cast
2+
from typing import Mapping, Optional, Dict, Union, List, Tuple, Any, TypedDict, cast
33

44
from google.protobuf import json_format
55

@@ -208,7 +208,7 @@ def delete(
208208
ids: Optional[List[str]] = None,
209209
delete_all: Optional[bool] = None,
210210
namespace: Optional[str] = None,
211-
filter: Optional[Dict[str, Union[str, float, int, bool, List, dict]]] = None,
211+
filter: Optional[Mapping[str, Union[str, float, int, bool, List, dict]]] = None,
212212
async_req: bool = False,
213213
**kwargs,
214214
) -> Union[DeleteResponse, PineconeGrpcFuture]:
@@ -234,7 +234,7 @@ def delete(
234234
Default is False.
235235
namespace (str): The namespace to delete vectors from [optional]
236236
If not specified, the default namespace is used.
237-
filter (Dict[str, Union[str, float, int, bool, List, dict]]):
237+
filter (Mapping[str, Union[str, float, int, bool, List, dict]]):
238238
If specified, the metadata filter here will be used to select the vectors to delete.
239239
This is mutually exclusive with specifying ids to delete in the ids param or using delete_all=True.
240240
See https://www.pinecone.io/docs/metadata-filtering/.. [optional]
@@ -292,7 +292,7 @@ def query(
292292
id: Optional[str] = None,
293293
namespace: Optional[str] = None,
294294
top_k: Optional[int] = None,
295-
filter: Optional[Dict[str, Union[str, float, int, bool, List, dict]]] = None,
295+
filter: Optional[Mapping[str, Union[str, float, int, bool, List, dict]]] = None,
296296
include_values: Optional[bool] = None,
297297
include_metadata: Optional[bool] = None,
298298
sparse_vector: Optional[Union[GRPCSparseValues, SparseVectorTypedDict]] = None,
@@ -322,7 +322,7 @@ def query(
322322
top_k (int): The number of results to return for each query. Must be an integer greater than 1.
323323
namespace (str): The namespace to fetch vectors from.
324324
If not specified, the default namespace is used. [optional]
325-
filter (Dict[str, Union[str, float, int, bool, List, dict]]):
325+
filter (Mapping[str, Union[str, float, int, bool, List, dict]]):
326326
The filter to apply. You can use vector metadata to limit your search.
327327
See https://www.pinecone.io/docs/metadata-filtering/.. [optional]
328328
include_values (bool): Indicates whether vector values are included in the response.
@@ -371,7 +371,7 @@ def update(
371371
id: str,
372372
async_req: bool = False,
373373
values: Optional[List[float]] = None,
374-
set_metadata: Optional[Dict[str, Union[str, float, int, bool, List[int], List[float], List[str]]]] = None,
374+
set_metadata: Optional[Mapping[str, Union[str, float, int, bool, List[int], List[float], List[str]]]] = None,
375375
namespace: Optional[str] = None,
376376
sparse_values: Optional[Union[GRPCSparseValues, SparseVectorTypedDict]] = None,
377377
**kwargs,
@@ -395,7 +395,7 @@ def update(
395395
async_req (bool): If True, the update operation will be performed asynchronously.
396396
Defaults to False. [optional]
397397
values (List[float]): vector values to set. [optional]
398-
set_metadata (Dict[str, Union[str, float, int, bool, List[int], List[float], List[str]]]]):
398+
set_metadata (Mapping[str, Union[str, float, int, bool, List[int], List[float], List[str]]]]):
399399
metadata to set for vector. [optional]
400400
namespace (str): Namespace name where to update the vector.. [optional]
401401
sparse_values: (Dict[str, Union[List[float], List[int]]]): sparse values to update for the vector.
@@ -429,7 +429,7 @@ def update(
429429
return self._wrap_grpc_call(self.stub.Update, request, timeout=timeout)
430430

431431
def describe_index_stats(
432-
self, filter: Optional[Dict[str, Union[str, float, int, bool, List, dict]]] = None, **kwargs
432+
self, filter: Optional[Mapping[str, Union[str, float, int, bool, List, dict]]] = None, **kwargs
433433
) -> DescribeIndexStatsResponse:
434434
"""
435435
The DescribeIndexStats operation returns statistics about the index's contents.
@@ -440,7 +440,7 @@ def describe_index_stats(
440440
>>> index.describe_index_stats(filter={'key': 'value'})
441441
442442
Args:
443-
filter (Dict[str, Union[str, float, int, bool, List, dict]]):
443+
filter (Mapping[str, Union[str, float, int, bool, List, dict]]):
444444
If this parameter is present, the operation only returns statistics for vectors that satisfy the filter.
445445
See https://www.pinecone.io/docs/metadata-filtering/.. [optional]
446446

0 commit comments

Comments
 (0)