Skip to content

Commit b1d68be

Browse files
authored
Merge branch 'zack-192-git-repo-settings' into test_lints
2 parents ca94ffd + a0e404c commit b1d68be

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

src/posit/connect/content.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333
from .tasks import Task
3434

3535

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"
4139

4240

4341
def _assert_content_guid(content_guid: str):
@@ -174,8 +172,10 @@ class ContentItemOwner(Resource):
174172

175173

176174
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+
179179
# Content Metadata
180180
title: NotRequired[str]
181181
description: NotRequired[str]
@@ -204,20 +204,47 @@ class _AttrsInit(TypedDict, total=False):
204204
default_py_environment_management: NotRequired[bool]
205205
service_account_name: NotRequired[str]
206206

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]
208213
owner_guid: NotRequired[str]
209214

215+
class _AttrsCreate(_AttrsBase):
216+
name: NotRequired[str]
217+
# owner_guid is not supported
218+
219+
@overload
210220
def __init__(
211221
self,
212222
/,
213223
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],
215242
) -> None:
216-
guid = _assert_guid_in_kwargs(kwargs)
243+
_assert_guid(guid)
217244

218245
ctx = Context(params.session, params.url)
219246
path = f"v1/content/{guid}"
220-
super().__init__(ctx, path, **kwargs)
247+
super().__init__(ctx, path, guid=guid, **kwargs)
221248

222249
def __getitem__(self, key: Any) -> Any:
223250
v = super().__getitem__(key)
@@ -501,7 +528,7 @@ def count(self) -> int:
501528

502529
def create(
503530
self,
504-
**attrs: Unpack[ContentItem._Attrs],
531+
**attrs: Unpack[ContentItem._AttrsCreate],
505532
) -> ContentItem:
506533
"""Create content.
507534

0 commit comments

Comments
 (0)