Skip to content

Commit 11f0a7f

Browse files
authored
Fix inference autocomplete (#498)
## Problem While implementing lazy loading and a package level .pyi file, we accidentally broke intellisense for some classes. ## Solution - Add missing exceptions to pyi - Remove type annotations on `pc.inference` that rely on values imported during `TYPE_CHECKING`. It seems like mypy and intellisense/autocomplete are able to infer these types without them being labeled explicitly. I think there is some sort of bug in the way autocomplete works because these type hints used with [TYPE_CHECKING](https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING) are valid and seem to work for typechecking purposes. ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) ## Test Plan Made a `7.0.1.dev1` dev build to confirm autocomplete behavior in different environments
2 parents 12b0bfa + c20fb4d commit 11f0a7f

File tree

5 files changed

+87
-18
lines changed

5 files changed

+87
-18
lines changed

pinecone/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@
66
from .deprecation_warnings import *
77
from .pinecone import Pinecone
88
from .pinecone_asyncio import PineconeAsyncio
9-
from .exceptions import *
9+
from .exceptions import (
10+
PineconeException,
11+
PineconeApiTypeError,
12+
PineconeApiValueError,
13+
PineconeApiAttributeError,
14+
PineconeApiKeyError,
15+
PineconeApiException,
16+
NotFoundException,
17+
UnauthorizedException,
18+
ForbiddenException,
19+
ServiceException,
20+
PineconeProtocolError,
21+
PineconeConfigurationError,
22+
ListConversionException,
23+
)
1024

1125
from .utils import __version__
1226

pinecone/__init__.pyi

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
from pinecone.config import Config
22
from pinecone.config import ConfigBuilder
33
from pinecone.config import PineconeConfig
4+
from .exceptions import (
5+
PineconeException,
6+
PineconeApiTypeError,
7+
PineconeApiValueError,
8+
PineconeApiAttributeError,
9+
PineconeApiKeyError,
10+
PineconeApiException,
11+
NotFoundException,
12+
UnauthorizedException,
13+
ForbiddenException,
14+
ServiceException,
15+
PineconeProtocolError,
16+
PineconeConfigurationError,
17+
ListConversionException,
18+
)
419
from pinecone.inference import (
20+
Inference,
21+
AsyncioInference,
522
RerankModel,
623
EmbedModel,
724
ModelInfo,
@@ -72,7 +89,23 @@ __all__ = [
7289
"Config",
7390
"ConfigBuilder",
7491
"PineconeConfig",
92+
# Exceptions
93+
"PineconeException",
94+
"PineconeApiTypeError",
95+
"PineconeApiValueError",
96+
"PineconeApiAttributeError",
97+
"PineconeApiKeyError",
98+
"PineconeApiException",
99+
"NotFoundException",
100+
"UnauthorizedException",
101+
"ForbiddenException",
102+
"ServiceException",
103+
"PineconeProtocolError",
104+
"PineconeConfigurationError",
105+
"ListConversionException",
75106
# Inference classes
107+
"Inference",
108+
"AsyncioInference",
76109
"RerankModel",
77110
"EmbedModel",
78111
"ModelInfo",

pinecone/exceptions/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
)
1616

1717
__all__ = [
18-
"PineconeConfigurationError",
19-
"PineconeProtocolError",
2018
"PineconeException",
21-
"PineconeApiAttributeError",
2219
"PineconeApiTypeError",
2320
"PineconeApiValueError",
21+
"PineconeApiAttributeError",
2422
"PineconeApiKeyError",
2523
"PineconeApiException",
2624
"NotFoundException",
2725
"UnauthorizedException",
2826
"ForbiddenException",
2927
"ServiceException",
28+
"PineconeProtocolError",
29+
"PineconeConfigurationError",
3030
"ListConversionException",
3131
]

pinecone/exceptions/exceptions.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def __init__(self, msg, path_to_item=None) -> None:
4949

5050

5151
class PineconeApiAttributeError(PineconeException, AttributeError):
52+
"""Raised when an attribute reference or assignment fails."""
53+
5254
def __init__(self, msg, path_to_item=None) -> None:
5355
"""
54-
Raised when an attribute reference or assignment fails.
55-
5656
Args:
5757
msg (str): the exception message
5858
@@ -85,6 +85,8 @@ def __init__(self, msg, path_to_item=None) -> None:
8585

8686

8787
class PineconeApiException(PineconeException):
88+
"""Raised when an API exception occurs."""
89+
8890
def __init__(self, status=None, reason=None, http_resp=None) -> None:
8991
if http_resp:
9092
self.status = http_resp.status
@@ -110,21 +112,29 @@ def __str__(self):
110112

111113

112114
class NotFoundException(PineconeApiException):
115+
"""Raised when a resource is not found."""
116+
113117
def __init__(self, status=None, reason=None, http_resp=None) -> None:
114118
super(NotFoundException, self).__init__(status, reason, http_resp)
115119

116120

117121
class UnauthorizedException(PineconeApiException):
122+
"""Raised when access to a resource is not authorized."""
123+
118124
def __init__(self, status=None, reason=None, http_resp=None) -> None:
119125
super(UnauthorizedException, self).__init__(status, reason, http_resp)
120126

121127

122128
class ForbiddenException(PineconeApiException):
129+
"""Raised when access to a resource is forbidden."""
130+
123131
def __init__(self, status=None, reason=None, http_resp=None) -> None:
124132
super(ForbiddenException, self).__init__(status, reason, http_resp)
125133

126134

127135
class ServiceException(PineconeApiException):
136+
"""Raised when a service error occurs."""
137+
128138
def __init__(self, status=None, reason=None, http_resp=None) -> None:
129139
super(ServiceException, self).__init__(status, reason, http_resp)
130140

@@ -151,3 +161,20 @@ class PineconeConfigurationError(PineconeException):
151161
class ListConversionException(PineconeException, TypeError):
152162
def __init__(self, message):
153163
super().__init__(message)
164+
165+
166+
__all__ = [
167+
"PineconeException",
168+
"PineconeApiTypeError",
169+
"PineconeApiValueError",
170+
"PineconeApiAttributeError",
171+
"PineconeApiKeyError",
172+
"PineconeApiException",
173+
"NotFoundException",
174+
"UnauthorizedException",
175+
"ForbiddenException",
176+
"ServiceException",
177+
"PineconeProtocolError",
178+
"PineconeConfigurationError",
179+
"ListConversionException",
180+
]

pinecone/pinecone.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515

1616
if TYPE_CHECKING:
1717
from pinecone.config import Config, OpenApiConfiguration
18-
from pinecone.db_data import (
19-
_Index as Index,
20-
_Inference as Inference,
21-
_IndexAsyncio as IndexAsyncio,
22-
)
23-
from pinecone.db_control import DBControl
18+
from pinecone.db_data import _Index as Index, _IndexAsyncio as IndexAsyncio
2419
from pinecone.db_control.index_host_store import IndexHostStore
2520
from pinecone.core.openapi.db_control.api.manage_indexes_api import ManageIndexesApi
2621
from pinecone.db_control.types import CreateIndexForModelEmbedTypedDict
@@ -94,18 +89,18 @@ def __init__(
9489
self._pool_threads = pool_threads
9590
""" @private """
9691

97-
self._inference: Optional["Inference"] = None # Lazy initialization
92+
self._inference = None # Lazy initialization
9893
""" @private """
9994

100-
self._db_control: Optional["DBControl"] = None # Lazy initialization
95+
self._db_control = None # Lazy initialization
10196
""" @private """
10297

10398
super().__init__() # Initialize PluginAware
10499

105100
@property
106-
def inference(self) -> "Inference":
101+
def inference(self):
107102
"""
108-
Inference is a namespace where an instance of the `pinecone.data.features.inference.inference.Inference` class is lazily created and cached.
103+
Inference is a namespace where an instance of the `pinecone.inference.Inference` class is lazily created and cached.
109104
"""
110105
if self._inference is None:
111106
from pinecone.inference import Inference
@@ -118,9 +113,9 @@ def inference(self) -> "Inference":
118113
return self._inference
119114

120115
@property
121-
def db(self) -> "DBControl":
116+
def db(self):
122117
"""
123-
DBControl is a namespace where an instance of the `pinecone.control.db_control.DBControl` class is lazily created and cached.
118+
DBControl is a namespace where an instance of the `pinecone.db_control.DBControl` class is lazily created and cached.
124119
"""
125120
if self._db_control is None:
126121
from pinecone.db_control import DBControl

0 commit comments

Comments
 (0)