Skip to content

Commit

Permalink
Use hasattr() instead of self.__dict__
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Nov 13, 2024
1 parent b525358 commit 137ba8b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/posit/connect/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,17 @@ def environment_variables(self) -> EnvVars:
def permissions(self) -> Permissions:
return Permissions(context_to_resource_parameters(self._ctx), self["guid"])

_owner: User

@property
def owner(self) -> dict:
if "_owner" not in self.__dict__:
if not hasattr(self, "_owner"):
# It is possible to get a content item that does not contain owner.
# "owner" is an optional additional request param.
# If it's not included, we can retrieve the information by `owner_guid`
from .users import Users

self._owner = Users(context_to_resource_parameters(self._ctx)).get(self["owner_guid"])
self._owner: User = Users(context_to_resource_parameters(self._ctx)).get(
self["owner_guid"]
)
return self._owner

@property
Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def jobs(self: ContentItemP) -> Jobs:
"""
# Do not cache result. `content.jobs` should always return the latest jobs.

# if self.__dict__.get("_jobs") is not None:
# if hasattr(self, "_jobs"):
# # Early return
# return self._jobs

Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/vanities.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class ContentItemVanityMixin:
@property
def vanity(self: ContentItemVanityP) -> str | None:
"""Get the vanity."""
if "_vanity" in self.__dict__ and self._vanity:
if hasattr(self, "_vanity") and self._vanity:
return self._vanity["path"]

try:
Expand Down

0 comments on commit 137ba8b

Please sign in to comment.