Skip to content

Commit

Permalink
style: fix/ignore flake8 errors in rdflib/plugins/sparql/ (#1964)
Browse files Browse the repository at this point in the history
These will eventually come up once `flakeheaven` baseline expires.

The actual problems should be fixed in conjunction with tests.

Only fixes are related to unused imports.
  • Loading branch information
aucampia committed May 21, 2022
1 parent 90ccb4f commit a3a4611
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 29 deletions.
8 changes: 4 additions & 4 deletions rdflib/plugins/sparql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
.. versionadded:: 4.0
"""

import sys
from typing import TYPE_CHECKING

SPARQL_LOAD_GRAPHS = True
"""
Expand All @@ -30,11 +32,9 @@

PLUGIN_ENTRY_POINT = "rdf.plugins.sparqleval"

import sys
from typing import TYPE_CHECKING, Any

from . import operators, parser, parserutils
from .processor import prepareQuery, prepareUpdate, processUpdate
from . import operators, parser, parserutils # noqa: E402
from .processor import prepareQuery, prepareUpdate, processUpdate # noqa: F401, E402

assert parser
assert operators
Expand Down
10 changes: 5 additions & 5 deletions rdflib/plugins/sparql/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def _addvar(term, varsknown):
return [x[1] for x in l_]


def triples(l):
def triples(l): # noqa: E741

l = reduce(lambda x, y: x + y, l)
l = reduce(lambda x, y: x + y, l) # noqa: E741
if (len(l) % 3) != 0:
raise Exception("these aint triples")
return reorderTriples((l[x], l[x + 1], l[x + 2]) for x in range(0, len(l), 3))
Expand Down Expand Up @@ -322,7 +322,7 @@ def translateGroupGraphPattern(graphPattern):
return G


class StopTraversal(Exception):
class StopTraversal(Exception): # noqa: N818
def __init__(self, rv):
self.rv = rv

Expand Down Expand Up @@ -794,7 +794,7 @@ def translateQuery(q, base=None, initNs=None):
return Query(prologue, res)


class ExpressionNotCoveredException(Exception):
class ExpressionNotCoveredException(Exception): # noqa: N818
pass


Expand Down Expand Up @@ -1112,7 +1112,7 @@ def sparql_query_text(node):
elif node.name == "MultiplicativeExpression":
left_side = convert_node_arg(node.expr)
multiplication = left_side
for i, operator in enumerate(node.op):
for i, operator in enumerate(node.op): # noqa: F402
multiplication += (
operator + " " + convert_node_arg(node.other[i]) + " "
)
Expand Down
2 changes: 1 addition & 1 deletion rdflib/plugins/sparql/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)
)

### adding dateTime datatypes
# adding dateTime datatypes

XSD_DateTime_DTs = set((XSD.dateTime, XSD.date, XSD.time))

Expand Down
3 changes: 0 additions & 3 deletions rdflib/plugins/sparql/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,16 @@
from rdflib.plugins.sparql import CUSTOM_EVALS, parser
from rdflib.plugins.sparql.aggregates import Aggregator
from rdflib.plugins.sparql.evalutils import (
_diff,
_ebv,
_eval,
_fillTemplate,
_filter,
_join,
_minus,
_val,
)
from rdflib.plugins.sparql.parserutils import CompValue, value
from rdflib.plugins.sparql.sparql import (
AlreadyBound,
Bindings,
FrozenBindings,
FrozenDict,
Query,
Expand Down
2 changes: 1 addition & 1 deletion rdflib/plugins/sparql/evalutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _ebv(expr, ctx):
elif isinstance(expr, Variable):
try:
return EBV(ctx[expr])
except:
except: # noqa: E722
return False
return False

Expand Down
12 changes: 6 additions & 6 deletions rdflib/plugins/sparql/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def Builtin_isNUMERIC(expr, ctx):
try:
numeric(expr.arg)
return Literal(True)
except:
except: # noqa: E722
return Literal(False)


Expand Down Expand Up @@ -669,15 +669,15 @@ def default_cast(e, ctx):
if not isinstance(x, Literal):
raise SPARQLError("Can only cast Literals to non-string data-types")

if x.datatype and not x.datatype in XSD_DTs:
if x.datatype and not x.datatype in XSD_DTs: # noqa: E713
raise SPARQLError("Cannot cast literal with unknown datatype: %r" % x.datatype)

if e.iri == XSD.dateTime:
if x.datatype and x.datatype not in (XSD.dateTime, XSD.string):
raise SPARQLError("Cannot cast %r to XSD:dateTime" % x.datatype)
try:
return Literal(isodate.parse_datetime(x), datatype=e.iri)
except:
except: # noqa: E722
raise SPARQLError("Cannot interpret '%r' as datetime" % x)

if x.datatype == XSD.dateTime:
Expand All @@ -686,21 +686,21 @@ def default_cast(e, ctx):
if e.iri in (XSD.float, XSD.double):
try:
return Literal(float(x), datatype=e.iri)
except:
except: # noqa: E722
raise SPARQLError("Cannot interpret '%r' as float" % x)

elif e.iri == XSD.decimal:
if "e" in x or "E" in x: # SPARQL/XSD does not allow exponents in decimals
raise SPARQLError("Cannot interpret '%r' as decimal" % x)
try:
return Literal(Decimal(x), datatype=e.iri)
except:
except: # noqa: E722
raise SPARQLError("Cannot interpret '%r' as decimal" % x)

elif e.iri == XSD.integer:
try:
return Literal(int(x), datatype=XSD.integer)
except:
except: # noqa: E722
raise SPARQLError("Cannot interpret '%r' as int" % x)

elif e.iri == XSD.boolean:
Expand Down
5 changes: 2 additions & 3 deletions rdflib/plugins/sparql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Literal,
OneOrMore,
Optional,
ParseException,
ParseResults,
Regex,
Suppress,
Expand Down Expand Up @@ -95,7 +94,7 @@ def expandTriples(terms):
# "Length of triple-list is not divisible by 3: %d!"%len(res)

# return [tuple(res[i:i+3]) for i in range(len(res)/3)]
except:
except: # noqa: E722
if DEBUG:
import traceback

Expand Down Expand Up @@ -1528,7 +1527,7 @@ def expandUnicodeEscapes(q):
def expand(m):
try:
return chr(int(m.group(1), 16))
except:
except: # noqa: E722
raise Exception("Invalid unicode code point: " + m)

return expandUnicodeEscapes_re.sub(expand, q)
Expand Down
2 changes: 1 addition & 1 deletion rdflib/plugins/sparql/parserutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,4 @@ def prettify_parsetree(t, indent="", depth=0):


# hurrah for circular imports
from rdflib.plugins.sparql.sparql import NotBoundError, SPARQLError
from rdflib.plugins.sparql.sparql import NotBoundError, SPARQLError # noqa: E402
2 changes: 1 addition & 1 deletion rdflib/plugins/sparql/results/jsonresults.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import IO, Any, Dict, Optional, TextIO, Union
from typing import IO, Any, Dict

from rdflib import BNode, Literal, URIRef, Variable
from rdflib.query import Result, ResultException, ResultParser, ResultSerializer
Expand Down
1 change: 0 additions & 1 deletion rdflib/plugins/sparql/results/tsvresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
LineEnd,
Literal,
Optional,
ParseException,
ParserElement,
Suppress,
ZeroOrMore,
Expand Down
4 changes: 2 additions & 2 deletions rdflib/plugins/sparql/sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, msg: Optional[str] = None):
SPARQLError.__init__(self, msg)


class AlreadyBound(SPARQLError):
class AlreadyBound(SPARQLError): # noqa: N818
"""Raised when trying to bind a variable that is already bound!"""

def __init__(self):
Expand Down Expand Up @@ -415,7 +415,7 @@ def absolutize(
return Literal(
iri.string, lang=iri.lang, datatype=self.absolutize(iri.datatype) # type: ignore[arg-type]
)
elif isinstance(iri, URIRef) and not ":" in iri:
elif isinstance(iri, URIRef) and not ":" in iri: # noqa: E713
return URIRef(iri, base=self.base)

return iri
Expand Down
2 changes: 1 addition & 1 deletion rdflib/plugins/sparql/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ def evalUpdate(graph, update, initBindings={}):
evalModify(ctx, u)
else:
raise Exception("Unknown update operation: %s" % (u,))
except:
except: # noqa: E722
if not u.silent:
raise

0 comments on commit a3a4611

Please sign in to comment.