|
33 | 33 | from .tasks import Task |
34 | 34 |
|
35 | 35 |
|
36 | | -def _assert_guid_in_kwargs(kwargs: object) -> str: |
37 | | - if not isinstance(kwargs, dict): |
38 | | - raise TypeError("Expected `kwargs` to be a dictionary") |
39 | | - assert "guid" in kwargs, "Missing 'guid' in `**kwargs`" |
40 | | - return kwargs["guid"] |
| 36 | +def _assert_guid(guid: str): |
| 37 | + assert isinstance(guid, str), "Expected 'guid' to be a string" |
| 38 | + assert len(guid) > 0, "Expected 'guid' to be non-empty" |
41 | 39 |
|
42 | 40 |
|
43 | 41 | def _assert_content_guid(content_guid: str): |
@@ -174,8 +172,10 @@ class ContentItemOwner(Resource): |
174 | 172 |
|
175 | 173 |
|
176 | 174 | class ContentItem(JobsMixin, VanityMixin, Resource): |
177 | | - class _AttrsInit(TypedDict, total=False): |
178 | | - name: Required[str] |
| 175 | + class _AttrsBase(TypedDict, total=False): |
| 176 | + # # `name` will be set by other _Attrs classes |
| 177 | + # name: str |
| 178 | + |
179 | 179 | # Content Metadata |
180 | 180 | title: NotRequired[str] |
181 | 181 | description: NotRequired[str] |
@@ -204,20 +204,47 @@ class _AttrsInit(TypedDict, total=False): |
204 | 204 | default_py_environment_management: NotRequired[bool] |
205 | 205 | service_account_name: NotRequired[str] |
206 | 206 |
|
207 | | - class _Attrs(_AttrsInit): |
| 207 | + class _AttrsNotRequired(_AttrsBase): |
| 208 | + name: NotRequired[str] |
| 209 | + owner_guid: NotRequired[str] |
| 210 | + |
| 211 | + class _Attrs(_AttrsBase): |
| 212 | + name: Required[str] |
208 | 213 | owner_guid: NotRequired[str] |
209 | 214 |
|
| 215 | + class _AttrsCreate(_AttrsBase): |
| 216 | + name: NotRequired[str] |
| 217 | + # owner_guid is not supported |
| 218 | + |
| 219 | + @overload |
210 | 220 | def __init__( |
211 | 221 | self, |
212 | 222 | /, |
213 | 223 | params: ResourceParameters, |
214 | | - **kwargs: Unpack[ContentItem._AttrsInit], |
| 224 | + guid: str, |
| 225 | + ) -> None: ... |
| 226 | + |
| 227 | + @overload |
| 228 | + def __init__( |
| 229 | + self, |
| 230 | + /, |
| 231 | + params: ResourceParameters, |
| 232 | + guid: str, |
| 233 | + **kwargs: Unpack[ContentItem._Attrs], |
| 234 | + ) -> None: ... |
| 235 | + |
| 236 | + def __init__( |
| 237 | + self, |
| 238 | + /, |
| 239 | + params: ResourceParameters, |
| 240 | + guid: str, |
| 241 | + **kwargs: Unpack[ContentItem._AttrsNotRequired], |
215 | 242 | ) -> None: |
216 | | - guid = _assert_guid_in_kwargs(kwargs) |
| 243 | + _assert_guid(guid) |
217 | 244 |
|
218 | 245 | ctx = Context(params.session, params.url) |
219 | 246 | path = f"v1/content/{guid}" |
220 | | - super().__init__(ctx, path, **kwargs) |
| 247 | + super().__init__(ctx, path, guid=guid, **kwargs) |
221 | 248 |
|
222 | 249 | def __getitem__(self, key: Any) -> Any: |
223 | 250 | v = super().__getitem__(key) |
@@ -501,7 +528,7 @@ def count(self) -> int: |
501 | 528 |
|
502 | 529 | def create( |
503 | 530 | self, |
504 | | - **attrs: Unpack[ContentItem._Attrs], |
| 531 | + **attrs: Unpack[ContentItem._AttrsCreate], |
505 | 532 | ) -> ContentItem: |
506 | 533 | """Create content. |
507 | 534 |
|
|
0 commit comments