summaryrefslogtreecommitdiff
path: root/rdflib/plugins/sparql/parserutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'rdflib/plugins/sparql/parserutils.py')
-rw-r--r--rdflib/plugins/sparql/parserutils.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/rdflib/plugins/sparql/parserutils.py b/rdflib/plugins/sparql/parserutils.py
index 6748a7f0..a936b046 100644
--- a/rdflib/plugins/sparql/parserutils.py
+++ b/rdflib/plugins/sparql/parserutils.py
@@ -1,10 +1,14 @@
from collections import OrderedDict
from types import MethodType
+from typing import TYPE_CHECKING, Any
from pyparsing import ParseResults, TokenConverter, originalTextFor
from rdflib import BNode, Variable
+if TYPE_CHECKING:
+ from rdflib.plugins.sparql.sparql import FrozenBindings
+
"""
NOTE: PyParsing setResultName/__call__ provides a very similar solution to this
@@ -38,7 +42,12 @@ the resulting CompValue
# Comp('Sum')( Param('x')(Number) + '+' + Param('y')(Number) )
-def value(ctx, val, variables=False, errors=False):
+def value(
+ ctx: "FrozenBindings",
+ val: Any,
+ variables: bool = False,
+ errors: bool = False,
+):
"""
utility function for evaluating something...
@@ -138,7 +147,7 @@ class CompValue(OrderedDict):
"""
- def __init__(self, name, **values):
+ def __init__(self, name: str, **values):
OrderedDict.__init__(self)
self.name = name
self.update(values)
@@ -164,7 +173,7 @@ class CompValue(OrderedDict):
def get(self, a, variables=False, errors=False):
return self._value(OrderedDict.get(self, a, a), variables, errors)
- def __getattr__(self, a):
+ def __getattr__(self, a: str) -> Any:
# Hack hack: OrderedDict relies on this
if a in ("_OrderedDict__root", "_OrderedDict__end"):
raise AttributeError()
@@ -174,6 +183,11 @@ class CompValue(OrderedDict):
# raise AttributeError('no such attribute '+a)
return None
+ if TYPE_CHECKING:
+ # this is here because properties are dynamically set on CompValue
+ def __setattr__(self, __name: str, __value: Any) -> None:
+ ...
+
class Expr(CompValue):
"""