Skip to content

Commit

Permalink
Minor additions
Browse files Browse the repository at this point in the history
Add return type annotation and some additional tests.
  • Loading branch information
aucampia committed Jul 31, 2023
1 parent fa02d99 commit 70f1d90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rdflib/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@

def _n3(
arg: Union["URIRef", "Path"], namespace_manager: Optional["NamespaceManager"] = None
):
) -> str:
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
if isinstance(arg, (SequencePath, AlternativePath)) and len(arg.args) > 1:
return "(%s)" % arg.n3(namespace_manager)
Expand Down
20 changes: 20 additions & 0 deletions test/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
f"<{RDF.type}>/<{RDFS.subClassOf}>*",
"rdf:type/rdfs:subClassOf*",
),
(
RDF.type / ((SequencePath(RDFS.subClassOf)) * "*"),
f"<{RDF.type}>/<{RDFS.subClassOf}>*",
"rdf:type/rdfs:subClassOf*",
),
(
RDF.type / RDFS.subClassOf * "*",
f"(<{RDF.type}>/<{RDFS.subClassOf}>)*",
Expand All @@ -68,6 +73,21 @@
f"!(<{RDF.type}>|<{RDFS.subClassOf}>)",
"!(rdf:type|rdfs:subClassOf)",
),
(
-(RDF.type | ((SequencePath(RDFS.subClassOf)) * "*")),
f"!(<{RDF.type}>|<{RDFS.subClassOf}>*)",
"!(rdf:type|rdfs:subClassOf*)",
),
(
SequencePath(RDFS.subClassOf),
f"<{RDFS.subClassOf}>",
"rdfs:subClassOf",
),
(
AlternativePath(RDFS.subClassOf),
f"<{RDFS.subClassOf}>",
"rdfs:subClassOf",
),
],
)
def test_paths_n3(
Expand Down

0 comments on commit 70f1d90

Please sign in to comment.