Skip to content

Commit 6fd1e9e

Browse files
committed
Add missed overloads and deprecations to users executors
1 parent 01ec14e commit 6fd1e9e

4 files changed

Lines changed: 105 additions & 6 deletions

File tree

tools/stubs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ def __parse_generics(self, node: ast.ClassDef):
7373
# We don't want to include ConnectionType
7474
continue
7575
new_bases.append(base)
76-
# if isinstance(base.value, ast.Name) and base.value.id == "_BaseExecutor":
77-
# # This is class from collections/queries
78-
# return []
7976
connection_type = ast.Name(id=self.__which_connection_type(), ctx=ast.Load())
8077
if len(new_bases) == 0:
8178
# no generics, we need to add the ConnectionType

weaviate/users/async_.pyi

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Dict, Generic, List, Optional, Union, cast
1+
from typing import Any, Dict, Generic, List, Literal, Optional, Union, cast, overload
2+
from typing_extensions import deprecated
23
from httpx import Response
34
from weaviate.connect import executor
45
from weaviate.connect.v4 import _ExpectedStatusCodes, ConnectionType
@@ -24,18 +25,45 @@ class _BaseAsync(_BaseExecutor[ConnectionAsync]):
2425

2526
class _UsersAsync(_UsersExecutor[ConnectionAsync]):
2627
async def get_my_user(self) -> OwnUser: ...
28+
@deprecated(
29+
"This method is deprecated and will be removed in Q4 25.\n Please use `users.db.get_assigned_roles` and/or `users.oidc.get_assigned_roles` instead."
30+
)
2731
async def get_assigned_roles(self, user_id: str) -> Dict[str, Role]: ...
32+
@deprecated(
33+
"This method is deprecated and will be removed in Q4 25.\n Please use `users.db.assign_roles` and/or `users.oidc.assign_roles` instead."
34+
)
2835
async def assign_roles(self, *, user_id: str, role_names: Union[str, List[str]]) -> None: ...
36+
@deprecated(
37+
"This method is deprecated and will be removed in Q4 25.\n Please use `users.db.revoke_roles` and/or `users.oidc.revoke_roles` instead."
38+
)
2939
async def revoke_roles(self, *, user_id: str, role_names: Union[str, List[str]]) -> None: ...
3040

3141
class _UsersOIDCAsync(_UsersOIDCExecutor[ConnectionAsync]):
42+
@overload
43+
async def get_assigned_roles(
44+
self, *, user_id: str, include_permissions: Literal[False] = False
45+
) -> Dict[str, RoleBase]: ...
46+
@overload
47+
async def get_assigned_roles(
48+
self, *, user_id: str, include_permissions: Literal[True]
49+
) -> Dict[str, Role]: ...
50+
@overload
3251
async def get_assigned_roles(
3352
self, *, user_id: str, include_permissions: bool = False
3453
) -> Union[Dict[str, Role], Dict[str, RoleBase]]: ...
3554
async def assign_roles(self, *, user_id: str, role_names: Union[str, List[str]]) -> None: ...
3655
async def revoke_roles(self, *, user_id: str, role_names: Union[str, List[str]]) -> None: ...
3756

3857
class _UsersDBAsync(_UsersDBExecutor[ConnectionAsync]):
58+
@overload
59+
async def get_assigned_roles(
60+
self, *, user_id: str, include_permissions: Literal[False] = False
61+
) -> Dict[str, RoleBase]: ...
62+
@overload
63+
async def get_assigned_roles(
64+
self, *, user_id: str, include_permissions: Literal[True]
65+
) -> Dict[str, Role]: ...
66+
@overload
3967
async def get_assigned_roles(
4068
self, *, user_id: str, include_permissions: bool = False
4169
) -> Union[Dict[str, Role], Dict[str, RoleBase]]: ...

weaviate/users/executor.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Dict, Generic, List, Optional, Union, cast
1+
from typing import Any, Dict, Generic, List, Literal, Optional, Union, cast, overload
2+
from typing_extensions import deprecated
23

34
from httpx import Response
45

@@ -144,6 +145,10 @@ def resp(res: Response) -> OwnUser:
144145
status_codes=_ExpectedStatusCodes(ok_in=[200], error="Get own roles"),
145146
)
146147

148+
@deprecated(
149+
"""This method is deprecated and will be removed in Q4 25.
150+
Please use `users.db.get_assigned_roles` and/or `users.oidc.get_assigned_roles` instead."""
151+
)
147152
def get_assigned_roles(self, user_id: str) -> executor.Result[Dict[str, Role]]:
148153
"""Get the roles assigned to a user.
149154
@@ -156,6 +161,10 @@ def get_assigned_roles(self, user_id: str) -> executor.Result[Dict[str, Role]]:
156161
# cast here because the deprecated method is only used in the deprecated class and this type is known
157162
return cast(Dict[str, Role], self._get_roles_of_user_deprecated(user_id))
158163

164+
@deprecated(
165+
"""This method is deprecated and will be removed in Q4 25.
166+
Please use `users.db.assign_roles` and/or `users.oidc.assign_roles` instead."""
167+
)
159168
def assign_roles(
160169
self,
161170
*,
@@ -174,6 +183,10 @@ def assign_roles(
174183
None,
175184
)
176185

186+
@deprecated(
187+
"""This method is deprecated and will be removed in Q4 25.
188+
Please use `users.db.revoke_roles` and/or `users.oidc.revoke_roles` instead."""
189+
)
177190
def revoke_roles(
178191
self,
179192
*,
@@ -194,6 +207,24 @@ def revoke_roles(
194207

195208

196209
class _UsersOIDCExecutor(Generic[ConnectionType], _BaseExecutor[ConnectionType]):
210+
@overload
211+
def get_assigned_roles(
212+
self, *, user_id: str, include_permissions: Literal[False] = False
213+
) -> executor.Result[Dict[str, RoleBase]]: ...
214+
215+
@overload
216+
def get_assigned_roles(
217+
self, *, user_id: str, include_permissions: Literal[True]
218+
) -> executor.Result[Dict[str, Role]]: ...
219+
220+
@overload
221+
def get_assigned_roles(
222+
self,
223+
*,
224+
user_id: str,
225+
include_permissions: bool = False,
226+
) -> executor.Result[Union[Dict[str, Role], Dict[str, RoleBase]]]: ...
227+
197228
def get_assigned_roles(
198229
self,
199230
*,
@@ -252,6 +283,21 @@ def revoke_roles(
252283

253284

254285
class _UsersDBExecutor(Generic[ConnectionType], _BaseExecutor[ConnectionType]):
286+
@overload
287+
def get_assigned_roles(
288+
self, *, user_id: str, include_permissions: Literal[False] = False
289+
) -> executor.Result[Dict[str, RoleBase]]: ...
290+
291+
@overload
292+
def get_assigned_roles(
293+
self, *, user_id: str, include_permissions: Literal[True]
294+
) -> executor.Result[Dict[str, Role]]: ...
295+
296+
@overload
297+
def get_assigned_roles(
298+
self, *, user_id: str, include_permissions: bool = False
299+
) -> executor.Result[Union[Dict[str, Role], Dict[str, RoleBase]]]: ...
300+
255301
def get_assigned_roles(
256302
self, *, user_id: str, include_permissions: bool = False
257303
) -> executor.Result[Union[Dict[str, Role], Dict[str, RoleBase]]]:

weaviate/users/sync.pyi

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Dict, Generic, List, Optional, Union, cast
1+
from typing import Any, Dict, Generic, List, Literal, Optional, Union, cast, overload
2+
from typing_extensions import deprecated
23
from httpx import Response
34
from weaviate.connect import executor
45
from weaviate.connect.v4 import _ExpectedStatusCodes, ConnectionType
@@ -24,18 +25,45 @@ class _Base(_BaseExecutor[ConnectionSync]):
2425

2526
class _Users(_UsersExecutor[ConnectionSync]):
2627
def get_my_user(self) -> OwnUser: ...
28+
@deprecated(
29+
"This method is deprecated and will be removed in Q4 25.\n Please use `users.db.get_assigned_roles` and/or `users.oidc.get_assigned_roles` instead."
30+
)
2731
def get_assigned_roles(self, user_id: str) -> Dict[str, Role]: ...
32+
@deprecated(
33+
"This method is deprecated and will be removed in Q4 25.\n Please use `users.db.assign_roles` and/or `users.oidc.assign_roles` instead."
34+
)
2835
def assign_roles(self, *, user_id: str, role_names: Union[str, List[str]]) -> None: ...
36+
@deprecated(
37+
"This method is deprecated and will be removed in Q4 25.\n Please use `users.db.revoke_roles` and/or `users.oidc.revoke_roles` instead."
38+
)
2939
def revoke_roles(self, *, user_id: str, role_names: Union[str, List[str]]) -> None: ...
3040

3141
class _UsersOIDC(_UsersOIDCExecutor[ConnectionSync]):
42+
@overload
43+
def get_assigned_roles(
44+
self, *, user_id: str, include_permissions: Literal[False] = False
45+
) -> Dict[str, RoleBase]: ...
46+
@overload
47+
def get_assigned_roles(
48+
self, *, user_id: str, include_permissions: Literal[True]
49+
) -> Dict[str, Role]: ...
50+
@overload
3251
def get_assigned_roles(
3352
self, *, user_id: str, include_permissions: bool = False
3453
) -> Union[Dict[str, Role], Dict[str, RoleBase]]: ...
3554
def assign_roles(self, *, user_id: str, role_names: Union[str, List[str]]) -> None: ...
3655
def revoke_roles(self, *, user_id: str, role_names: Union[str, List[str]]) -> None: ...
3756

3857
class _UsersDB(_UsersDBExecutor[ConnectionSync]):
58+
@overload
59+
def get_assigned_roles(
60+
self, *, user_id: str, include_permissions: Literal[False] = False
61+
) -> Dict[str, RoleBase]: ...
62+
@overload
63+
def get_assigned_roles(
64+
self, *, user_id: str, include_permissions: Literal[True]
65+
) -> Dict[str, Role]: ...
66+
@overload
3967
def get_assigned_roles(
4068
self, *, user_id: str, include_permissions: bool = False
4169
) -> Union[Dict[str, Role], Dict[str, RoleBase]]: ...

0 commit comments

Comments
 (0)