Skip to content

Commit cd69c9b

Browse files
committed
Move uuid property to Releasable base class, fixing None guard and validation in KGProxy
1 parent b096606 commit cd69c9b

3 files changed

Lines changed: 10 additions & 14 deletions

File tree

fairgraph/base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020

2121
from __future__ import annotations
22-
from typing import TYPE_CHECKING, Optional, Dict, List, Any
22+
from typing import TYPE_CHECKING, Optional, Dict, List, Any, Union
2323
from enum import Enum
2424
import logging
25+
from uuid import UUID
2526
from warnings import warn
2627

2728
from .errors import AuthorizationError
@@ -67,6 +68,14 @@ class Releasable(Resolvable): # KGObject, KGProxy
6768
id: Optional[str]
6869
remote_data: Optional[JSONdict]
6970

71+
@property
72+
def uuid(self) -> Union[str, None]:
73+
if self.id is not None:
74+
value = self.id.split("/")[-1]
75+
return str(UUID(value))
76+
else:
77+
return None
78+
7079
def children(
7180
self, client: KGClient, follow_links: Optional[Dict[str, Any]] = None
7281
) -> List[Releasable]:

fairgraph/kgobject.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,6 @@ def from_alias(
355355
)
356356
return candidates[0]
357357

358-
@property
359-
def uuid(self) -> Union[str, None]:
360-
# todo: consider using client._kg_client.uuid_from_absolute_id
361-
if self.id is not None:
362-
value = self.id.split("/")[-1]
363-
return str(UUID(value))
364-
else:
365-
return None
366-
367358
@classmethod
368359
def uri_from_uuid(cls, uuid: str, client: KGClient) -> str:
369360
"""Convert an instances short-form identifier (a UUID) into the long-form (a URI)"""

fairgraph/kgproxy.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ def __ne__(self, other):
161161
not isinstance(other, self.__class__) or set(self.classes).isdisjoint(other.classes) or self.id != other.id
162162
)
163163

164-
@property
165-
def uuid(self) -> str:
166-
return self.id.split("/")[-1]
167-
168164
def delete(self, client: KGClient, ignore_not_found: bool = True):
169165
"""Delete the instance which this proxy represents"""
170166
try:

0 commit comments

Comments
 (0)