@@ -18,24 +18,24 @@ Song = NewType('Song', URIRef)
UnixTime = NewType('UnixTime', float)
# Alternate output range for a device. Instead of outputting 0.0 to
# 1.0, you can map that range into, say, 0.2 to 0.7
OutputRange = NewType('OutputRange', Tuple[float, float])
_ObjType = TypeVar('_ObjType')
def _isSubclass2(t1: Type, t2: Type) -> bool:
"""same as issubclass but t1 can be a NewType"""
if hasattr(t1, '__supertype__'):
t1 = t1.__superType__
t1 = t1.__supertype__
return issubclass(t1, t2)
def typedValue(objType: Type[_ObjType], graph, subj, pred) -> _ObjType:
"""graph.value(subj, pred) with a given return type.
If objType is not an rdflib.Node, we toPython() the value."""
obj = graph.value(subj, pred)
if obj is None:
raise ValueError()
conv = obj if _isSubclass2(objType, Node) else obj.toPython()
return cast(objType, conv)
\ No newline at end of file
Status change: