|
1 | | -from typing import Generic, TypeVar |
| 1 | +from typing import Generic, Literal, TypeVar, cast |
2 | 2 | from uuid import UUID |
3 | 3 |
|
4 | 4 | from pydantic import AliasChoices, Field, TypeAdapter, field_validator |
@@ -158,13 +158,15 @@ def set_users( |
158 | 158 | users_payload = [] |
159 | 159 | if users is not None and len(users) > 0: |
160 | 160 | if isinstance(users[0], CollectionUser): |
| 161 | + users = cast(list[CollectionUser], users) |
161 | 162 | users_payload = [ |
162 | | - user.model_dump( # type: ignore |
| 163 | + user.model_dump( |
163 | 164 | exclude={"CollectionId"}, by_alias=True, mode="json" |
164 | 165 | ) |
165 | 166 | for user in users |
166 | 167 | ] |
167 | 168 | else: |
| 169 | + users = cast(list[UUID], users) |
168 | 170 | users_payload = [ |
169 | 171 | { |
170 | 172 | "id": str(user_id), |
@@ -351,28 +353,26 @@ def invite( |
351 | 353 | ): |
352 | 354 | collections_payload = [] |
353 | 355 | if collections is not None and len(collections) > 0: |
354 | | - assert collections is not None |
355 | 356 | for coll in collections: |
356 | 357 | if isinstance(coll, UserCollection): |
357 | | - assert isinstance(coll, UserCollection) |
| 358 | + coll = cast(UserCollection, coll) |
| 359 | + ex: dict[str, Literal[True]] = {"UserId": True} |
358 | 360 | collections_payload.append( |
359 | 361 | coll.model_dump( |
360 | 362 | by_alias=True, |
361 | 363 | mode="json", |
362 | | - exclude={"UserId": True}, |
| 364 | + exclude=ex, |
363 | 365 | ) |
364 | 366 | ) |
365 | 367 | else: |
366 | | - coll_id = "" |
367 | 368 | if isinstance(coll, OrganizationCollection): |
368 | | - assert isinstance(coll, OrganizationCollection) |
| 369 | + coll = cast(OrganizationCollection, coll) |
369 | 370 | coll_id = str(coll.Id) |
370 | | - elif isinstance(collections[0], UUID): |
371 | | - assert isinstance(coll, UUID) |
| 371 | + elif isinstance(coll, UUID): |
| 372 | + coll = cast(UUID, coll) |
372 | 373 | coll_id = str(coll) |
373 | 374 | else: |
374 | | - assert isinstance(coll, str) |
375 | | - coll_id = coll |
| 375 | + coll_id = cast(str, coll) |
376 | 376 | collections_payload.append( |
377 | 377 | { |
378 | 378 | "id": coll_id, |
|
0 commit comments