Skip to content

Commit 13bda09

Browse files
committed
Switched the utility to all class methods -- this is invoked BEFORE an instance is constructed
1 parent 075ce76 commit 13bda09

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

linkml_runtime/utils/yamlutils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,16 @@ def _class_for(cls, attribute: str, uri_or_curie: Union[str, URIRef]) -> Optiona
254254
return match
255255
return None
256256

257-
def _class_for_uri(self, uri: str, use_model_uri: bool = False) -> Optional["YAMLRoot"]:
257+
@classmethod
258+
def _class_for_uri(cls: Type["YAMLRoot"], uri: str, use_model_uri: bool = False) -> Optional[Type["YAMLRoot"]]:
258259
"""
259260
Return the self or descendant of self having with a matching class uri
260261
"""
261-
return self.__class__._class_for('class_model_uri' if use_model_uri else 'class_class_uri', URIRef(uri))
262+
return cls._class_for('class_model_uri' if use_model_uri else 'class_class_uri', URIRef(uri))
262263

263-
def _class_for_curie(self, curie: str) -> Optional["YAMLRoot"]:
264-
return self.__class__._class_for('class_class_curie', curie)
264+
@classmethod
265+
def _class_for_curie(cls: Type["YAMLRoot"], curie: str) -> Optional[Type["YAMLRoot"]]:
266+
return cls._class_for('class_class_curie', curie)
265267

266268
# ==================
267269
# Error intercepts

tests/test_utils/test_poly_dataclasses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class PolyDataclassTestCase(unittest.TestCase):
55
def test_class_for_uri(self):
66
""" Test various class lookup options """
7-
e = Element(name="Test")
7+
e = Element
88

99
# Test class URI
1010
cls = e._class_for_uri(LINKML.ClassDefinition)

0 commit comments

Comments
 (0)