diff options
author | Joern Hees <dev@joernhees.de> | 2015-12-29 19:53:35 +0100 |
---|---|---|
committer | Joern Hees <dev@joernhees.de> | 2015-12-29 20:17:34 +0100 |
commit | cf6fbe2f0a1f4f9de11d36e44efa2e4a3ef2a1ec (patch) | |
tree | 77efcb88422f048b99d1e4c4c599c6ada89e69b7 | |
parent | 609b0e06425c9487faee4ad6bf8835b1b2b28ba9 (diff) | |
download | rdflib-fix_sparql_raise_unbound.tar.gz |
raise instead of return NotBoundError exception and adapted handling codefix_sparql_raise_unbound
-rw-r--r-- | rdflib/plugins/sparql/aggregates.py | 13 | ||||
-rw-r--r-- | rdflib/plugins/sparql/evalutils.py | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/rdflib/plugins/sparql/aggregates.py b/rdflib/plugins/sparql/aggregates.py index 86bfb25a..571bac4f 100644 --- a/rdflib/plugins/sparql/aggregates.py +++ b/rdflib/plugins/sparql/aggregates.py @@ -83,13 +83,13 @@ def agg_Max(a, group, bindings): def agg_Count(a, group, bindings): - c = 0 for x in group: try: if a.vars != '*': - val = _eval(a.vars, x) - if isinstance(val, NotBoundError): + try: + _eval(a.vars, x) + except NotBoundError: continue c += 1 except: @@ -101,10 +101,11 @@ def agg_Count(a, group, bindings): def agg_Sample(a, group, bindings): for ctx in group: - val = _eval(a.vars, ctx) - if not isinstance(val, NotBoundError): - bindings[a.res] = val + try: + bindings[a.res] = _eval(a.vars, ctx) break + except NotBoundError: + pass def agg_GroupConcat(a, group, bindings): diff --git a/rdflib/plugins/sparql/evalutils.py b/rdflib/plugins/sparql/evalutils.py index 77fe33ef..b1e500bb 100644 --- a/rdflib/plugins/sparql/evalutils.py +++ b/rdflib/plugins/sparql/evalutils.py @@ -70,7 +70,7 @@ def _eval(expr, ctx): try: return ctx[expr] except KeyError: - return NotBoundError("Variable %s is not bound" % expr) + raise NotBoundError("Variable %s is not bound" % expr) elif isinstance(expr, CompValue): raise Exception( "Weird - _eval got a CompValue without evalfn! %r" % expr) |