Skip to content

Commit a3a4611

Browse files
authored
style: fix/ignore flake8 errors in rdflib/plugins/sparql/ (#1964)
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.
1 parent 90ccb4f commit a3a4611

File tree

12 files changed

+24
-29
lines changed

12 files changed

+24
-29
lines changed

rdflib/plugins/sparql/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
.. versionadded:: 4.0
55
"""
66

7+
import sys
8+
from typing import TYPE_CHECKING
79

810
SPARQL_LOAD_GRAPHS = True
911
"""
@@ -30,11 +32,9 @@
3032

3133
PLUGIN_ENTRY_POINT = "rdf.plugins.sparqleval"
3234

33-
import sys
34-
from typing import TYPE_CHECKING, Any
3535

36-
from . import operators, parser, parserutils
37-
from .processor import prepareQuery, prepareUpdate, processUpdate
36+
from . import operators, parser, parserutils # noqa: E402
37+
from .processor import prepareQuery, prepareUpdate, processUpdate # noqa: F401, E402
3838

3939
assert parser
4040
assert operators

rdflib/plugins/sparql/algebra.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ def _addvar(term, varsknown):
129129
return [x[1] for x in l_]
130130

131131

132-
def triples(l):
132+
def triples(l): # noqa: E741
133133

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

324324

325-
class StopTraversal(Exception):
325+
class StopTraversal(Exception): # noqa: N818
326326
def __init__(self, rv):
327327
self.rv = rv
328328

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

796796

797-
class ExpressionNotCoveredException(Exception):
797+
class ExpressionNotCoveredException(Exception): # noqa: N818
798798
pass
799799

800800

@@ -1112,7 +1112,7 @@ def sparql_query_text(node):
11121112
elif node.name == "MultiplicativeExpression":
11131113
left_side = convert_node_arg(node.expr)
11141114
multiplication = left_side
1115-
for i, operator in enumerate(node.op):
1115+
for i, operator in enumerate(node.op): # noqa: F402
11161116
multiplication += (
11171117
operator + " " + convert_node_arg(node.other[i]) + " "
11181118
)

rdflib/plugins/sparql/datatypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030
)
3131

32-
### adding dateTime datatypes
32+
# adding dateTime datatypes
3333

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

rdflib/plugins/sparql/evaluate.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,16 @@
2828
from rdflib.plugins.sparql import CUSTOM_EVALS, parser
2929
from rdflib.plugins.sparql.aggregates import Aggregator
3030
from rdflib.plugins.sparql.evalutils import (
31-
_diff,
3231
_ebv,
3332
_eval,
3433
_fillTemplate,
35-
_filter,
3634
_join,
3735
_minus,
3836
_val,
3937
)
4038
from rdflib.plugins.sparql.parserutils import CompValue, value
4139
from rdflib.plugins.sparql.sparql import (
4240
AlreadyBound,
43-
Bindings,
4441
FrozenBindings,
4542
FrozenDict,
4643
Query,

rdflib/plugins/sparql/evalutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _ebv(expr, ctx):
5353
elif isinstance(expr, Variable):
5454
try:
5555
return EBV(ctx[expr])
56-
except:
56+
except: # noqa: E722
5757
return False
5858
return False
5959

rdflib/plugins/sparql/operators.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def Builtin_isNUMERIC(expr, ctx):
6565
try:
6666
numeric(expr.arg)
6767
return Literal(True)
68-
except:
68+
except: # noqa: E722
6969
return Literal(False)
7070

7171

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

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

675675
if e.iri == XSD.dateTime:
676676
if x.datatype and x.datatype not in (XSD.dateTime, XSD.string):
677677
raise SPARQLError("Cannot cast %r to XSD:dateTime" % x.datatype)
678678
try:
679679
return Literal(isodate.parse_datetime(x), datatype=e.iri)
680-
except:
680+
except: # noqa: E722
681681
raise SPARQLError("Cannot interpret '%r' as datetime" % x)
682682

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

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

700700
elif e.iri == XSD.integer:
701701
try:
702702
return Literal(int(x), datatype=XSD.integer)
703-
except:
703+
except: # noqa: E722
704704
raise SPARQLError("Cannot interpret '%r' as int" % x)
705705

706706
elif e.iri == XSD.boolean:

rdflib/plugins/sparql/parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Literal,
1616
OneOrMore,
1717
Optional,
18-
ParseException,
1918
ParseResults,
2019
Regex,
2120
Suppress,
@@ -95,7 +94,7 @@ def expandTriples(terms):
9594
# "Length of triple-list is not divisible by 3: %d!"%len(res)
9695

9796
# return [tuple(res[i:i+3]) for i in range(len(res)/3)]
98-
except:
97+
except: # noqa: E722
9998
if DEBUG:
10099
import traceback
101100

@@ -1528,7 +1527,7 @@ def expandUnicodeEscapes(q):
15281527
def expand(m):
15291528
try:
15301529
return chr(int(m.group(1), 16))
1531-
except:
1530+
except: # noqa: E722
15321531
raise Exception("Invalid unicode code point: " + m)
15331532

15341533
return expandUnicodeEscapes_re.sub(expand, q)

rdflib/plugins/sparql/parserutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,4 @@ def prettify_parsetree(t, indent="", depth=0):
270270

271271

272272
# hurrah for circular imports
273-
from rdflib.plugins.sparql.sparql import NotBoundError, SPARQLError
273+
from rdflib.plugins.sparql.sparql import NotBoundError, SPARQLError # noqa: E402

rdflib/plugins/sparql/results/jsonresults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import IO, Any, Dict, Optional, TextIO, Union
2+
from typing import IO, Any, Dict
33

44
from rdflib import BNode, Literal, URIRef, Variable
55
from rdflib.query import Result, ResultException, ResultParser, ResultSerializer

rdflib/plugins/sparql/results/tsvresults.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
LineEnd,
1212
Literal,
1313
Optional,
14-
ParseException,
1514
ParserElement,
1615
Suppress,
1716
ZeroOrMore,

0 commit comments

Comments
 (0)