fix: formatting of SequencePath and AlternativePath (#2504) · RDFLib/rdflib@9c73581 (original) (raw)
`@@ -213,6 +213,15 @@
`
213
213
`ZeroOrOne = "?"
`
214
214
``
215
215
``
``
216
`+
def _n3(
`
``
217
`+
arg: Union["URIRef", "Path"], namespace_manager: Optional["NamespaceManager"] = None
`
``
218
`+
) -> str:
`
``
219
`+
type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
`
``
220
`+
if isinstance(arg, (SequencePath, AlternativePath)) and len(arg.args) > 1:
`
``
221
`+
return "(%s)" % arg.n3(namespace_manager)
`
``
222
`+
return arg.n3(namespace_manager) # type: ignore[union-attr]
`
``
223
+
``
224
+
216
225
`@total_ordering
`
217
226
`class Path:
`
218
227
`or: Callable[["Path", Union["URIRef", "Path"]], "AlternativePath"]
`
`@@ -260,8 +269,7 @@ def repr(self) -> str:
`
260
269
`return "Path(~%s)" % (self.arg,)
`
261
270
``
262
271
`def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
`
263
``
`-
type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
`
264
``
`-
return "^%s" % self.arg.n3(namespace_manager) # type: ignore[union-attr]
`
``
272
`+
return "^%s" % _n3(self.arg, namespace_manager)
`
265
273
``
266
274
``
267
275
`class SequencePath(Path):
`
`@@ -318,8 +326,7 @@ def repr(self) -> str:
`
318
326
`return "Path(%s)" % " / ".join(str(x) for x in self.args)
`
319
327
``
320
328
`def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
`
321
``
`-
type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
`
322
``
`-
return "/".join(a.n3(namespace_manager) for a in self.args) # type: ignore[union-attr]
`
``
329
`+
return "/".join(_n3(a, namespace_manager) for a in self.args)
`
323
330
``
324
331
``
325
332
`class AlternativePath(Path):
`
`@@ -345,8 +352,7 @@ def repr(self) -> str:
`
345
352
`return "Path(%s)" % " | ".join(str(x) for x in self.args)
`
346
353
``
347
354
`def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
`
348
``
`-
type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
`
349
``
`-
return "|".join(a.n3(namespace_manager) for a in self.args) # type: ignore[union-attr]
`
``
355
`+
return "|".join(_n3(a, namespace_manager) for a in self.args)
`
350
356
``
351
357
``
352
358
`class MulPath(Path):
`
`@@ -470,8 +476,7 @@ def repr(self) -> str:
`
470
476
`return "Path(%s%s)" % (self.path, self.mod)
`
471
477
``
472
478
`def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
`
473
``
`-
type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
`
474
``
`-
return "%s%s" % (self.path.n3(namespace_manager), self.mod) # type: ignore[union-attr]
`
``
479
`+
return "%s%s" % (_n3(self.path, namespace_manager), self.mod)
`
475
480
``
476
481
``
477
482
`class NegatedPath(Path):
`
`@@ -505,8 +510,7 @@ def repr(self) -> str:
`
505
510
`return "Path(! %s)" % ",".join(str(x) for x in self.args)
`
506
511
``
507
512
`def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
`
508
``
`-
type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
`
509
``
`-
return "!(%s)" % ("|".join(arg.n3(namespace_manager) for arg in self.args)) # type: ignore[union-attr]
`
``
513
`+
return "!(%s)" % ("|".join(_n3(arg, namespace_manager) for arg in self.args))
`
510
514
``
511
515
``
512
516
`class PathList(list):
`