Skip to content

Commit

Permalink
[review] implement review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
  • Loading branch information
meretp committed Apr 5, 2023
1 parent eb39f78 commit f8115a6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/spdx/parser/rdf/graph_parsing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ def get_correctly_typed_triples(
subject: Optional[Node] = None,
predicate: Optional[Node] = None,
_object: Optional[Node] = None,
) -> Tuple[URIRef, Node, Union[BNode, Literal, URIRef]]:
# this is a helper method to enforce some rdf types for the triples to bo compatible with the
) -> Tuple[Union[BNode, URIRef], Node, Union[BNode, Literal, URIRef]]:
# this is a helper method to cast some rdf types from graph.triples() to be compatible with the
# code that follows
for s, p, o in graph.triples((subject, predicate, _object)):
if not isinstance(s, (BNode, URIRef)):
logger.append(
f"Warning: Subject should be of type BNode or URIRef, but is {type(s).__name__}. "
f"Warning: Subject {s} should be of type BNode or URIRef, but is {type(s).__name__}. "
f"This might lead to a failure."
)
if not isinstance(o, (BNode, Literal, URIRef)):
logger.append(
f"Warning: Object should be of type BNode, Literal or URIRef, but is {type(o).__name__}. "
f"Warning: Object {o} should be of type BNode, Literal or URIRef, but is {type(o).__name__}. "
f"This might lead to a failure."
)
yield s, p, o
Expand All @@ -136,10 +136,12 @@ def get_value_from_graph(
default: Optional[Any] = None,
_any: Optional[bool] = True,
) -> Optional[Union[URIRef, Literal, BNode]]:
# this is a helper method to cast some rdf types from graph.value() to be compatible with the
# code that follows
value = graph.value(subject=subject, predicate=predicate, object=_object, default=default, any=_any)
if value and not isinstance(value, (URIRef, Literal, BNode)):
logger.append(
f"Warning: Object should be of type BNode, Literal or URIRef, but is {type(value).__name__}. "
f"Warning: Node {value} should be of type BNode, Literal or URIRef, but is {type(value).__name__}. "
f"This might lead to a failure."
)
return value

0 comments on commit f8115a6

Please sign in to comment.