Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable.__repr__ should return a python representation string, not n3 #488

Merged
merged 1 commit into from
Jun 22, 2015

Conversation

joernhees
Copy link
Member

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:

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').

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')`.
@joernhees joernhees added bug Something isn't working enhancement New feature or request labels Jun 22, 2015
@joernhees joernhees self-assigned this Jun 22, 2015
@joernhees joernhees added this to the rdflib 4.2.1 milestone Jun 22, 2015
@joernhees joernhees changed the title Variable.__repr__ returns a python representation string, not n3 Variable.__repr__ should return a python representation string, not n3 Jun 22, 2015
joernhees added a commit that referenced this pull request Jun 22, 2015
Variable.__repr__ should return a python representation string, not n3
@joernhees joernhees merged commit 56248df into RDFLib:master Jun 22, 2015
@joernhees joernhees deleted the fix_variable_repr branch June 22, 2015 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant