diff options
author | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2017-01-18 21:01:40 +0100 |
---|---|---|
committer | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2017-01-18 21:02:49 +0100 |
commit | c1b29aea3803e6e25287cfdf794f030538bdfa7c (patch) | |
tree | fb47ab0b8181967eed19adafaee3226dc913380e /rdflib/plugins/sparql/algebra.py | |
parent | 87414fdd938238f1d73eb8b2ae2344c42cdbe2c0 (diff) | |
download | rdflib-c1b29aea3803e6e25287cfdf794f030538bdfa7c.tar.gz |
Fixed some BIND scoping issuesfix-issue-580
Made Extend eval only forget vars not bound outside.
Made Extend only collect vars not in "expr"
This fixes #580
Diffstat (limited to 'rdflib/plugins/sparql/algebra.py')
-rw-r--r-- | rdflib/plugins/sparql/algebra.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/rdflib/plugins/sparql/algebra.py b/rdflib/plugins/sparql/algebra.py index 4f24740f..026b58e4 100644 --- a/rdflib/plugins/sparql/algebra.py +++ b/rdflib/plugins/sparql/algebra.py @@ -435,16 +435,21 @@ def _addVars(x, children): if isinstance(x, Variable): return set([x]) elif isinstance(x, CompValue): - x["_vars"] = set(reduce(operator.or_, children, set())) - if x.name == "Bind": - return set([x.var]) - elif x.name == 'SubSelect': - if x.projection: - s = set(v.var or v.evar for v in x.projection) - else: - s = set() + if x.name == "Extend": + # vars only used in the expr for a bind should not be included + x["_vars"] = reduce(operator.or_, [ child for child,part in zip(children,x) if part!='expr' ], set()) + + return set([x.var]) # perhaps this should expose all vars here too? + else: + x["_vars"] = set(reduce(operator.or_, children, set())) + + if x.name == 'SubSelect': + if x.projection: + s = set(v.var or v.evar for v in x.projection) + else: + s = set() - return s + return s return reduce(operator.or_, children, set()) |