diff options
author | Joern Hees <dev@joernhees.de> | 2015-06-22 18:38:34 +0200 |
---|---|---|
committer | Joern Hees <dev@joernhees.de> | 2015-06-22 18:38:34 +0200 |
commit | 7e2397b1c0b588cfa84013218087101cd8c65785 (patch) | |
tree | d827203814611fcb00aa41655d494211acde58d9 | |
parent | fe3fa522b48e787fa87dc1156e1a10bd6671b62c (diff) | |
download | rdflib-7e2397b1c0b588cfa84013218087101cd8c65785.tar.gz |
Variable.__repr__ returns a python representation string, not n3
For other terms like `URIRef`, `Literal` and `BNodes` we return a
`repr` string that is a string representation of the term and allows
re-creating the object when passed to `eval`. Variable isn't that
consistent it seems:
```python
In [1]: import rdflib
INFO:rdflib:RDFLib Version: 4.2.1-dev
In [2]: eval(repr(rdflib.term.URIRef('foo')))
Out[2]: rdflib.term.URIRef(u'foo')
In [3]: eval(repr(rdflib.term.Variable('foo')))
File "<string>", line 1
?foo
^
SyntaxError: invalid syntax
```
https://docs.python.org/2/library/functions.html#func-repr doesn't
really enforce this, but it's nice to have for debugging for example.
This commit returns a repr like `rdflib.term.Variable('foo')`.
-rw-r--r-- | rdflib/term.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/rdflib/term.py b/rdflib/term.py index 285bdeb9..91cc06ea 100644 --- a/rdflib/term.py +++ b/rdflib/term.py @@ -1527,7 +1527,12 @@ class Variable(Identifier): return unicode.__new__(cls, value) def __repr__(self): - return self.n3() + if self.__class__ is Variable: + clsName = "rdflib.term.Variable" + else: + clsName = self.__class__.__name__ + + return """%s(%s)""" % (clsName, super(Variable, self).__repr__()) def toPython(self): return "?%s" % self |