Skip to content

Commit

Permalink
Toplevel n80x (#2046)
Browse files Browse the repository at this point in the history
Handful of fixes for PEP8 naming convention violations.
  • Loading branch information
Graham Higgins committed Jul 28, 2022
1 parent 0856ac8 commit 3e2987b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 53 deletions.
38 changes: 19 additions & 19 deletions rdflib/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class Collection(object):
>>> from rdflib.graph import Graph
>>> from pprint import pprint
>>> listName = BNode()
>>> listname = BNode()
>>> g = Graph('Memory')
>>> listItem1 = BNode()
>>> listItem2 = BNode()
>>> g.add((listName, RDF.first, Literal(1))) # doctest: +ELLIPSIS
>>> g.add((listname, RDF.first, Literal(1))) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> g.add((listName, RDF.rest, listItem1)) # doctest: +ELLIPSIS
>>> g.add((listname, RDF.rest, listItem1)) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> g.add((listItem1, RDF.first, Literal(2))) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
Expand All @@ -27,7 +27,7 @@ class Collection(object):
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> g.add((listItem2, RDF.first, Literal(3))) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> c = Collection(g,listName)
>>> c = Collection(g,listname)
>>> pprint([term.n3() for term in c])
[u'"1"^^<http://www.w3.org/2001/XMLSchema#integer>',
u'"2"^^<http://www.w3.org/2001/XMLSchema#integer>',
Expand All @@ -51,13 +51,13 @@ def __init__(self, graph, uri, seq=[]):
def n3(self):
"""
>>> from rdflib.graph import Graph
>>> listName = BNode()
>>> listname = BNode()
>>> g = Graph('Memory')
>>> listItem1 = BNode()
>>> listItem2 = BNode()
>>> g.add((listName, RDF.first, Literal(1))) # doctest: +ELLIPSIS
>>> g.add((listname, RDF.first, Literal(1))) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> g.add((listName, RDF.rest, listItem1)) # doctest: +ELLIPSIS
>>> g.add((listname, RDF.rest, listItem1)) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> g.add((listItem1, RDF.first, Literal(2))) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
Expand All @@ -67,7 +67,7 @@ def n3(self):
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> g.add((listItem2, RDF.first, Literal(3))) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> c = Collection(g, listName)
>>> c = Collection(g, listname)
>>> print(c.n3()) #doctest: +NORMALIZE_WHITESPACE
( "1"^^<http://www.w3.org/2001/XMLSchema#integer>
"2"^^<http://www.w3.org/2001/XMLSchema#integer>
Expand Down Expand Up @@ -96,21 +96,21 @@ def index(self, item):
"""
Returns the 0-based numerical index of the item in the list
"""
listName = self.uri
listname = self.uri
index = 0
while True:
if (listName, RDF.first, item) in self.graph:
if (listname, RDF.first, item) in self.graph:
return index
else:
newLink = list(self.graph.objects(listName, RDF.rest))
newlink = list(self.graph.objects(listname, RDF.rest))
index += 1
if newLink == [RDF.nil]:
if newlink == [RDF.nil]:
raise ValueError("%s is not in %s" % (item, self.uri))
elif not newLink:
elif not newlink:
raise Exception("Malformed RDF Collection: %s" % self.uri)
else:
assert len(newLink) == 1, "Malformed RDF Collection: %s" % self.uri
listName = newLink[0]
assert len(newlink) == 1, "Malformed RDF Collection: %s" % self.uri
listname = newlink[0]

def __getitem__(self, key):
"""TODO"""
Expand Down Expand Up @@ -183,8 +183,8 @@ def __delitem__(self, key):
pass
elif key == len(self) - 1:
# the tail
priorLink = self._get_container(key - 1)
self.graph.set((priorLink, RDF.rest, RDF.nil))
priorlink = self._get_container(key - 1)
self.graph.set((priorlink, RDF.rest, RDF.nil))
graph.remove((current, None, None))
else:
next = self._get_container(key + 1)
Expand All @@ -210,9 +210,9 @@ def _end(self):
def append(self, item):
"""
>>> from rdflib.graph import Graph
>>> listName = BNode()
>>> listname = BNode()
>>> g = Graph()
>>> c = Collection(g,listName,[Literal(1),Literal(2)])
>>> c = Collection(g,listname,[Literal(1),Literal(2)])
>>> links = [
... list(g.subjects(object=i, predicate=RDF.first))[0] for i in c]
>>> len([i for i in links if (i, RDF.rest, RDF.nil) in g])
Expand Down
4 changes: 2 additions & 2 deletions rdflib/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _total_seconds(td):
return result


class _runtime(object):
class _runtime(object): # noqa: N801
def __init__(self, label):
self.label = label

Expand All @@ -137,7 +137,7 @@ def wrapped_f(*args, **kwargs):
return wrapped_f


class _call_count(object):
class _call_count(object): # noqa: N801
def __init__(self, label):
self.label = label

Expand Down
4 changes: 2 additions & 2 deletions rdflib/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ def index(self, item):
pred = self.graph.predicates(self.uri, item)
if not pred:
raise ValueError("%s is not in %s" % (item, "container"))
LI_INDEX = URIRef(str(RDF) + "_")
li_index = URIRef(str(RDF) + "_")

i = None
for p in pred:
i = int(p.replace(LI_INDEX, ""))
i = int(p.replace(li_index, ""))
return i

def __getitem__(self, key):
Expand Down
63 changes: 37 additions & 26 deletions rdflib/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,74 +103,74 @@
A more complete set of tests:
>>> list(evalPath(g, (None, e.p1/e.p2, None)))==[(e.a, e.e)]
>>> list(eval_path(g, (None, e.p1/e.p2, None)))==[(e.a, e.e)]
True
>>> list(evalPath(g, (e.a, e.p1|e.p2, None)))==[(e.a,e.c), (e.a,e.f)]
>>> list(eval_path(g, (e.a, e.p1|e.p2, None)))==[(e.a,e.c), (e.a,e.f)]
True
>>> list(evalPath(g, (e.c, ~e.p1, None))) == [ (e.c, e.a) ]
>>> list(eval_path(g, (e.c, ~e.p1, None))) == [ (e.c, e.a) ]
True
>>> list(evalPath(g, (e.a, e.p1*ZeroOrOne, None))) == [(e.a, e.a), (e.a, e.c)]
>>> list(eval_path(g, (e.a, e.p1*ZeroOrOne, None))) == [(e.a, e.a), (e.a, e.c)]
True
>>> list(evalPath(g, (e.c, e.p3*OneOrMore, None))) == [
>>> list(eval_path(g, (e.c, e.p3*OneOrMore, None))) == [
... (e.c, e.g), (e.c, e.h), (e.c, e.a)]
True
>>> list(evalPath(g, (e.c, e.p3*ZeroOrMore, None))) == [(e.c, e.c),
>>> list(eval_path(g, (e.c, e.p3*ZeroOrMore, None))) == [(e.c, e.c),
... (e.c, e.g), (e.c, e.h), (e.c, e.a)]
True
>>> list(evalPath(g, (e.a, -e.p1, None))) == [(e.a, e.f)]
>>> list(eval_path(g, (e.a, -e.p1, None))) == [(e.a, e.f)]
True
>>> list(evalPath(g, (e.a, -(e.p1|e.p2), None))) == []
>>> list(eval_path(g, (e.a, -(e.p1|e.p2), None))) == []
True
>>> list(evalPath(g, (e.g, -~e.p2, None))) == [(e.g, e.j)]
>>> list(eval_path(g, (e.g, -~e.p2, None))) == [(e.g, e.j)]
True
>>> list(evalPath(g, (e.e, ~(e.p1/e.p2), None))) == [(e.e, e.a)]
>>> list(eval_path(g, (e.e, ~(e.p1/e.p2), None))) == [(e.e, e.a)]
True
>>> list(evalPath(g, (e.a, e.p1/e.p3/e.p3, None))) == [(e.a, e.h)]
>>> list(eval_path(g, (e.a, e.p1/e.p3/e.p3, None))) == [(e.a, e.h)]
True
>>> list(evalPath(g, (e.q, e.px*OneOrMore, None)))
>>> list(eval_path(g, (e.q, e.px*OneOrMore, None)))
[(rdflib.term.URIRef('ex:q'), rdflib.term.URIRef('ex:q'))]
>>> list(evalPath(g, (None, e.p1|e.p2, e.c)))
>>> list(eval_path(g, (None, e.p1|e.p2, e.c)))
[(rdflib.term.URIRef('ex:a'), rdflib.term.URIRef('ex:c'))]
>>> list(evalPath(g, (None, ~e.p1, e.a))) == [ (e.c, e.a) ]
>>> list(eval_path(g, (None, ~e.p1, e.a))) == [ (e.c, e.a) ]
True
>>> list(evalPath(g, (None, e.p1*ZeroOrOne, e.c))) # doctest: +NORMALIZE_WHITESPACE
>>> list(eval_path(g, (None, e.p1*ZeroOrOne, e.c))) # doctest: +NORMALIZE_WHITESPACE
[(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:c')),
(rdflib.term.URIRef('ex:a'), rdflib.term.URIRef('ex:c'))]
>>> list(evalPath(g, (None, e.p3*OneOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
>>> list(eval_path(g, (None, e.p3*OneOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
[(rdflib.term.URIRef('ex:h'), rdflib.term.URIRef('ex:a')),
(rdflib.term.URIRef('ex:g'), rdflib.term.URIRef('ex:a')),
(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:a'))]
>>> list(evalPath(g, (None, e.p3*ZeroOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
>>> list(eval_path(g, (None, e.p3*ZeroOrMore, e.a))) # doctest: +NORMALIZE_WHITESPACE
[(rdflib.term.URIRef('ex:a'), rdflib.term.URIRef('ex:a')),
(rdflib.term.URIRef('ex:h'), rdflib.term.URIRef('ex:a')),
(rdflib.term.URIRef('ex:g'), rdflib.term.URIRef('ex:a')),
(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:a'))]
>>> list(evalPath(g, (None, -e.p1, e.f))) == [(e.a, e.f)]
>>> list(eval_path(g, (None, -e.p1, e.f))) == [(e.a, e.f)]
True
>>> list(evalPath(g, (None, -(e.p1|e.p2), e.c))) == []
>>> list(eval_path(g, (None, -(e.p1|e.p2), e.c))) == []
True
>>> list(evalPath(g, (None, -~e.p2, e.j))) == [(e.g, e.j)]
>>> list(eval_path(g, (None, -~e.p2, e.j))) == [(e.g, e.j)]
True
>>> list(evalPath(g, (None, ~(e.p1/e.p2), e.a))) == [(e.e, e.a)]
>>> list(eval_path(g, (None, ~(e.p1/e.p2), e.a))) == [(e.e, e.a)]
True
>>> list(evalPath(g, (None, e.p1/e.p3/e.p3, e.h))) == [(e.a, e.h)]
>>> list(eval_path(g, (None, e.p1/e.p3/e.p3, e.h))) == [(e.a, e.h)]
True
>>> list(evalPath(g, (e.q, e.px*OneOrMore, None)))
>>> list(eval_path(g, (e.q, e.px*OneOrMore, None)))
[(rdflib.term.URIRef('ex:q'), rdflib.term.URIRef('ex:q'))]
>>> list(evalPath(g, (e.c, (e.p2|e.p3)*ZeroOrMore, e.j)))
>>> list(eval_path(g, (e.c, (e.p2|e.p3)*ZeroOrMore, e.j)))
[(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:j'))]
No vars specified:
>>> sorted(list(evalPath(g, (None, e.p3*OneOrMore, None)))) #doctest: +NORMALIZE_WHITESPACE
>>> sorted(list(eval_path(g, (None, e.p3*OneOrMore, None)))) #doctest: +NORMALIZE_WHITESPACE
[(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:a')),
(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:g')),
(rdflib.term.URIRef('ex:c'), rdflib.term.URIRef('ex:h')),
Expand All @@ -180,7 +180,7 @@
"""


import warnings
from functools import total_ordering
from typing import TYPE_CHECKING, Callable, Iterator, Optional, Tuple, Union

Expand Down Expand Up @@ -462,6 +462,17 @@ def path_sequence(self, other):


def evalPath(graph, t):
warnings.warn(
DeprecationWarning(
"rdflib.path.evalPath() is deprecated, use the (snake-cased) eval_path(). "
"The mixed-case evalPath() function name is incompatible with PEP8 "
"recommendations and will be replaced by eval_path() in rdflib 7.0.0."
)
)
return eval_path(graph, t)


def eval_path(graph, t):
return ((s, o) for s, p, o in graph.triples(t))


Expand Down
4 changes: 2 additions & 2 deletions rdflib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(
self.class_name = class_name
self._class: Optional[Type[PluginT]] = None

def getClass(self) -> Type[PluginT]:
def getClass(self) -> Type[PluginT]: # noqa: N802
if self._class is None:
module = __import__(self.module_path, globals(), locals(), [""])
self._class = getattr(module, self.class_name)
Expand All @@ -112,7 +112,7 @@ def __init__(self, name: str, kind: Type[PluginT], ep: "EntryPoint"):
self.ep = ep
self._class: Optional[Type[PluginT]] = None

def getClass(self) -> Type[PluginT]:
def getClass(self) -> Type[PluginT]: # noqa: N802
if self._class is None:
self._class = self.ep.load()
return self._class
Expand Down
4 changes: 2 additions & 2 deletions rdflib/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Processor(object):
def __init__(self, graph):
pass

def query(self, strOrQuery, initBindings={}, initNs={}, DEBUG=False):
def query(self, strOrQuery, initBindings={}, initNs={}, DEBUG=False): # noqa: N803
pass


Expand All @@ -57,7 +57,7 @@ class update method.
def __init__(self, graph):
pass

def update(self, strOrQuery, initBindings={}, initNs={}):
def update(self, strOrQuery, initBindings={}, initNs={}): # noqa: N803
pass


Expand Down

0 comments on commit 3e2987b

Please sign in to comment.