Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aucampia committed Feb 19, 2023
1 parent 49aebeb commit aa10537
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion rdflib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Parser(object):
def __init__(self):
pass

def parse(self, source: "InputSource", sink: "Graph"):
def parse(self, source: "InputSource", sink: "Graph") -> None:
pass


Expand Down
16 changes: 11 additions & 5 deletions rdflib/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def __repr__(self) -> str:
return "Path(~%s)" % (self.arg,)

def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
return "^%s" % self.arg.n3(namespace_manager)
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
return "^%s" % self.arg.n3(namespace_manager) # type: ignore[union-attr]


class SequencePath(Path):
Expand Down Expand Up @@ -312,7 +313,8 @@ def __repr__(self) -> str:
return "Path(%s)" % " / ".join(str(x) for x in self.args)

def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
return "/".join(a.n3(namespace_manager) for a in self.args)
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
return "/".join(a.n3(namespace_manager) for a in self.args) # type: ignore[union-attr]


class AlternativePath(Path):
Expand All @@ -338,7 +340,9 @@ def __repr__(self) -> str:
return "Path(%s)" % " | ".join(str(x) for x in self.args)

def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
return "|".join(a.n3(namespace_manager) for a in self.args)
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
return "|".join(a.n3(namespace_manager) for a in self.args) # type: ignore[union-attr]


class MulPath(Path):
def __init__(self, path: Union[Path, URIRef], mod: _MulPathMod):
Expand Down Expand Up @@ -461,7 +465,8 @@ def __repr__(self) -> str:
return "Path(%s%s)" % (self.path, self.mod)

def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
return "%s%s" % (self.path.n3(namespace_manager), self.mod)
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
return "%s%s" % (self.path.n3(namespace_manager), self.mod) # type: ignore[union-attr]


class NegatedPath(Path):
Expand Down Expand Up @@ -495,7 +500,8 @@ def __repr__(self) -> str:
return "Path(! %s)" % ",".join(str(x) for x in self.args)

def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
return "!(%s)" % ("|".join(arg.n3(namespace_manager) for arg in self.args))
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
return "!(%s)" % ("|".join(arg.n3(namespace_manager) for arg in self.args)) # type: ignore[union-attr]


class PathList(list):
Expand Down
8 changes: 2 additions & 6 deletions rdflib/plugins/parsers/hext.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,8 @@ def parse(self, source: InputSource, graph: Graph, **kwargs: Any) -> None: # ty
for l in fp: # noqa: E741
self._parse_hextuple(cg, self._load_json_line(l))
elif hasattr(source, "_InputSource__bytefile"):
# type error: "InputSource" has no attribute "_InputSource__bytefile"
if hasattr(source._InputSource__bytefile, "wrapped"): # type: ignore[attr-defined]
# type error: "InputSource" has no attribute "_InputSource__bytefile"
if hasattr(source._InputSource__bytefile, "wrapped"):
for (
l # noqa: E741
) in (
source._InputSource__bytefile.wrapped.strip().splitlines() # type: ignore[attr-defined]
):
) in source._InputSource__bytefile.wrapped.strip().splitlines():
self._parse_hextuple(cg, self._load_json_line(l))
4 changes: 2 additions & 2 deletions rdflib/plugins/parsers/notation3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,8 +1950,8 @@ def normalise(
# return f.universals[n]
# f.universals[n] = f.newBlankNode()
# return f.universals[n]

return n
# type error: Incompatible return value type (got "Union[int, _AnyT]", expected "Union[URIRef, Literal, BNode, _AnyT]") [return-value]
return n # type: ignore[return-value]

def intern(self, something: _AnyT) -> _AnyT:
return something
Expand Down
4 changes: 2 additions & 2 deletions rdflib/plugins/parsers/trig.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def parse(self, source: InputSource, graph: Graph, encoding: str = "utf-8") -> N
if encoding not in [None, "utf-8"]:
raise Exception(
# type error: Unsupported left operand type for % ("Tuple[str, str]")
("TriG files are always utf-8 encoded, ", "I was passed: %s")
% encoding # type: ignore[operator]
("TriG files are always utf-8 encoded, ", "I was passed: %s") # type: ignore[operator]
% encoding
)

# we're currently being handed a Graph, not a ConjunctiveGraph
Expand Down
3 changes: 2 additions & 1 deletion rdflib/plugins/sparql/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def evalServiceQuery(ctx: QueryContext, part: CompValue):
res = {}
match = re.match(
"^service <(.*)>[ \n]*{(.*)}[ \n]*$",
part.get("service_string", ""),
# type error: Argument 2 to "get" of "CompValue" has incompatible type "str"; expected "bool" [arg-type]
part.get("service_string", ""), # type: ignore[arg-type]
re.DOTALL | re.I,
)

Expand Down
8 changes: 2 additions & 6 deletions rdflib/plugins/sparql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1530,9 +1530,7 @@ def expand(m):

def parseQuery(q: Union[bytes, str, IO]) -> ParseResults:
if hasattr(q, "read"):
# type error: Item "bytes" of "Union[bytes, str, IO[Any]]" has no attribute "read"
# type error: Item "str" of "Union[bytes, str, IO[Any]]" has no attribute "read"
q = q.read() # type: ignore[union-attr]
q = q.read()
if isinstance(q, bytes):
q = q.decode("utf-8")

Expand All @@ -1543,9 +1541,7 @@ def parseQuery(q: Union[bytes, str, IO]) -> ParseResults:

def parseUpdate(q: Union[bytes, str, IO]) -> CompValue:
if hasattr(q, "read"):
# type error: Item "bytes" of "Union[bytes, str, IO[Any]]" has no attribute "read"
# type error: Item "str" of "Union[bytes, str, IO[Any]]" has no attribute "read"
q = q.read() # type: ignore[union-attr]
q = q.read()

if isinstance(q, bytes):
q = q.decode("utf-8")
Expand Down
2 changes: 2 additions & 0 deletions rdflib/plugins/sparql/parserutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def __init__(self, name: str, expr):
Param.__init__(self, name, expr, True)


_ValT = TypeVar("_ValT")


class CompValue(OrderedDict):

Expand Down
10 changes: 5 additions & 5 deletions rdflib/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@
"""


from typing import TYPE_CHECKING, Any, TypeVar, overload, Union

from pyparsing import Optional
from typing import TYPE_CHECKING, Any, Optional, Union, overload

from rdflib.namespace import RDF
from rdflib.paths import Path
Expand Down Expand Up @@ -355,7 +353,9 @@ def add(self, p: _PredicateType, o: _ObjectType):

self._graph.add((self._identifier, p, o))

def remove(self, p: _PredicateType, o: Optional[_ObjectType] = None):
def remove(
self, p: _PredicateType, o: Optional[Union[_ObjectType, Resource]] = None
):
if isinstance(o, Resource):
o = o._identifier

Expand All @@ -370,7 +370,7 @@ def set(self, p: _PredicateType, o: _ObjectType):
def subjects(self, predicate=None): # rev
return self._resources(self._graph.subjects(predicate, self._identifier))

def predicates(self, o: Optional[_ObjectType] = None):
def predicates(self, o: Optional[Union[_ObjectType, Resource]] = None):
if isinstance(o, Resource):
o = o._identifier

Expand Down

0 comments on commit aa10537

Please sign in to comment.