Skip to content

Commit

Permalink
Remove (TypeCheck|SubjectType|PredicateType|ObjectType)Error and re…
Browse files Browse the repository at this point in the history
…lated

Also remove
`check_(context|subject|predicate|object|statement|pattern)`.

It seems nothing is using these exceptions and functions.
  • Loading branch information
aucampia committed Apr 4, 2022
1 parent 3325ac2 commit 408399f
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 212 deletions.
61 changes: 0 additions & 61 deletions rdflib/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

__all__ = [
"Error",
"TypeCheckError",
"SubjectTypeError",
"PredicateTypeError",
"ObjectTypeError",
"ContextTypeError",
"ParserError",
]

Expand All @@ -20,62 +15,6 @@ def __init__(self, msg=None):
Exception.__init__(self, msg)
self.msg = msg


class TypeCheckError(Error):
"""Parts of assertions are subject to type checks."""

def __init__(self, node):
Error.__init__(self, node)
self.type = type(node)
self.node = node


class SubjectTypeError(TypeCheckError):
"""Subject of an assertion must be an instance of URIRef."""

def __init__(self, node):
TypeCheckError.__init__(self, node)
self.msg = "Subject must be instance of URIRef or BNode: %s(%s)" % (
self.node,
self.type,
)


class PredicateTypeError(TypeCheckError):
"""Predicate of an assertion must be an instance of URIRef."""

def __init__(self, node):
TypeCheckError.__init__(self, node)
self.msg = "Predicate must be a URIRef instance: %s(%s)" % (
self.node,
self.type,
)


class ObjectTypeError(TypeCheckError):
"""Object of an assertion must be an instance of URIRef, Literal,
or BNode."""

def __init__(self, node):
TypeCheckError.__init__(self, node)
self.msg = (
"\
Object must be instance of URIRef, Literal, or BNode: %s(%s)"
% (self.node, self.type)
)


class ContextTypeError(TypeCheckError):
"""Context of an assertion must be an instance of URIRef."""

def __init__(self, node):
TypeCheckError.__init__(self, node)
self.msg = "Context must be instance of URIRef or BNode: %s(%s)" % (
self.node,
self.type,
)


class ParserError(Error):
"""RDF Parser error."""

Expand Down
66 changes: 0 additions & 66 deletions rdflib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
* date_time
* parse_date_time
Statement and component type checkers
* check_context
* check_subject
* check_predicate
* check_object
* check_statement
* check_pattern
"""

from calendar import timegm
Expand All @@ -41,10 +32,6 @@

from os.path import splitext

from rdflib.exceptions import ContextTypeError
from rdflib.exceptions import ObjectTypeError
from rdflib.exceptions import PredicateTypeError
from rdflib.exceptions import SubjectTypeError
import rdflib.graph # avoid circular dependency
from rdflib.namespace import Namespace, XSD
from rdflib.namespace import NamespaceManager
Expand All @@ -62,12 +49,6 @@
"from_n3",
"date_time",
"parse_date_time",
"check_context",
"check_subject",
"check_predicate",
"check_object",
"check_statement",
"check_pattern",
"guess_format",
"find_roots",
"get_tree",
Expand Down Expand Up @@ -235,53 +216,6 @@ def from_n3(s: str, default=None, backend=None, nsm=None):
return BNode(s)


def check_context(c):
if not (isinstance(c, URIRef) or isinstance(c, BNode)):
raise ContextTypeError("%s:%s" % (c, type(c)))


def check_subject(s):
"""Test that s is a valid subject identifier."""
if not (isinstance(s, URIRef) or isinstance(s, BNode)):
raise SubjectTypeError(s)


def check_predicate(p):
"""Test that p is a valid predicate identifier."""
if not isinstance(p, URIRef):
raise PredicateTypeError(p)


def check_object(o):
"""Test that o is a valid object identifier."""
if not (isinstance(o, URIRef) or isinstance(o, Literal) or isinstance(o, BNode)):
raise ObjectTypeError(o)


def check_statement(triple):
(s, p, o) = triple
if not (isinstance(s, URIRef) or isinstance(s, BNode)):
raise SubjectTypeError(s)

if not isinstance(p, URIRef):
raise PredicateTypeError(p)

if not (isinstance(o, URIRef) or isinstance(o, Literal) or isinstance(o, BNode)):
raise ObjectTypeError(o)


def check_pattern(triple):
(s, p, o) = triple
if s and not (isinstance(s, URIRef) or isinstance(s, BNode)):
raise SubjectTypeError(s)

if p and not isinstance(p, URIRef):
raise PredicateTypeError(p)

if o and not (
isinstance(o, URIRef) or isinstance(o, Literal) or isinstance(o, BNode)
):
raise ObjectTypeError(o)


def date_time(t=None, local_time_zone=False):
Expand Down
52 changes: 0 additions & 52 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
from rdflib.term import URIRef
from rdflib import util
from rdflib import XSD
from rdflib.exceptions import SubjectTypeError
from rdflib.exceptions import PredicateTypeError
from rdflib.exceptions import ObjectTypeError
from rdflib.exceptions import ContextTypeError

n3source = """\
@prefix : <http://www.w3.org/2000/10/swap/Primer#>.
Expand Down Expand Up @@ -343,53 +339,5 @@ def test_util_from_n3_not_escapes_xf(self) -> None:
literal_str = str(util.from_n3(f'"{string}"'))
self.assertEqual(literal_str, f"{string}")


class TestUtilCheckers(unittest.TestCase):
def setUp(self):
self.c = URIRef("http://example.com")
self.s = BNode("http://example.com")
self.p = URIRef("http://example.com/predicates/isa")
self.o = Literal("Objectification")

def test_util_checker_exceptions(self):
c = "http://example.com"
self.assertRaises(ContextTypeError, util.check_context, c)
self.assertRaises(SubjectTypeError, util.check_subject, c)
self.assertRaises(PredicateTypeError, util.check_predicate, c)
self.assertRaises(ObjectTypeError, util.check_object, c)

def test_util_check_context(self):
res = util.check_context(self.c)
self.assertTrue(res == None)

def test_util_check_subject(self):
res = util.check_subject(self.s)
self.assertTrue(res == None)

def test_util_check_predicate(self):
res = util.check_predicate(self.p)
self.assertTrue(res == None)

def test_util_check_object(self):
res = util.check_object(self.o)
self.assertTrue(res == None)

def test_util_check_statement(self):
c = "http://example.com"
self.assertRaises(SubjectTypeError, util.check_statement, (c, self.p, self.o))
self.assertRaises(PredicateTypeError, util.check_statement, (self.s, c, self.o))
self.assertRaises(ObjectTypeError, util.check_statement, (self.s, self.p, c))
res = util.check_statement((self.s, self.p, self.o))
self.assertTrue(res == None)

def test_util_check_pattern(self):
c = "http://example.com"
self.assertRaises(SubjectTypeError, util.check_pattern, (c, self.p, self.o))
self.assertRaises(PredicateTypeError, util.check_pattern, (self.s, c, self.o))
self.assertRaises(ObjectTypeError, util.check_pattern, (self.s, self.p, c))
res = util.check_pattern((self.s, self.p, self.o))
self.assertTrue(res == None)


if __name__ == "__main__":
unittest.main()
33 changes: 0 additions & 33 deletions test/type_check.py

This file was deleted.

0 comments on commit 408399f

Please sign in to comment.