Skip to content

Commit

Permalink
docs: remove Unicode literals from docstrings (#2604)
Browse files Browse the repository at this point in the history
Unicode literals (`u'ẋẏż'`) are redundant in Python 3 as all strings
support Unicode. This change eliminates the use of Unicode literals from
docstrings so that the `ALLOW_UNICODE` option flag is no longer needed
for doctests.

See also:
- #2383
- #2378
  • Loading branch information
aucampia authored Sep 25, 2023
1 parent 093b529 commit cc7350f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
6 changes: 3 additions & 3 deletions rdflib/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class Collection:
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> c = Collection(g,listname)
>>> pprint([term.n3() for term in c])
[u'"1"^^<http://www.w3.org/2001/XMLSchema#integer>',
u'"2"^^<http://www.w3.org/2001/XMLSchema#integer>',
u'"3"^^<http://www.w3.org/2001/XMLSchema#integer>']
['"1"^^<http://www.w3.org/2001/XMLSchema#integer>',
'"2"^^<http://www.w3.org/2001/XMLSchema#integer>',
'"3"^^<http://www.w3.org/2001/XMLSchema#integer>']
>>> Literal(1) in c
True
Expand Down
18 changes: 9 additions & 9 deletions rdflib/extras/describer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
>>>
>>> class Person:
... def __init__(self):
... self.first_name = u"Some"
... self.last_name = u"Body"
... self.first_name = "Some"
... self.last_name = "Body"
... self.username = "some1"
... self.presentation = u"Just a Python & RDF hacker."
... self.presentation = "Just a Python & RDF hacker."
... self.image = "/images/persons/" + self.username + ".jpg"
... self.site = "http://example.net/"
... self.start_date = datetime.date(2009, 9, 4)
... def get_full_name(self):
... return u" ".join([self.first_name, self.last_name])
... return " ".join([self.first_name, self.last_name])
... def get_absolute_url(self):
... return "/persons/" + self.username
... def get_thumbnail_url(self):
Expand Down Expand Up @@ -130,7 +130,7 @@ def about(self, subject, **kws):
rdflib.term.BNode(...)
>>> d.about("http://example.org/")
>>> d._current()
rdflib.term.URIRef(u'http://example.org/')
rdflib.term.URIRef('http://example.org/')
"""
kws.setdefault("base", self.base)
Expand All @@ -152,7 +152,7 @@ def value(self, p, v, **kws):
>>> d = Describer(about="http://example.org/")
>>> d.value(RDFS.label, "Example")
>>> d.graph.value(URIRef('http://example.org/'), RDFS.label)
rdflib.term.Literal(u'Example')
rdflib.term.Literal('Example')
"""
v = cast_value(v, **kws)
Expand All @@ -173,15 +173,15 @@ def rel(self, p, o=None, **kws):
>>> d = Describer(about="/", base="http://example.org/")
>>> _ctxt = d.rel(RDFS.seeAlso, "/about")
>>> d.graph.value(URIRef('http://example.org/'), RDFS.seeAlso)
rdflib.term.URIRef(u'http://example.org/about')
rdflib.term.URIRef('http://example.org/about')
>>> with d.rel(RDFS.seeAlso, "/more"):
... d.value(RDFS.label, "More")
>>> (URIRef('http://example.org/'), RDFS.seeAlso,
... URIRef('http://example.org/more')) in d.graph
True
>>> d.graph.value(URIRef('http://example.org/more'), RDFS.label)
rdflib.term.Literal(u'More')
rdflib.term.Literal('More')
"""

Expand All @@ -208,7 +208,7 @@ def rev(self, p, s=None, **kws):
... URIRef('http://example.org/')) in d.graph
True
>>> d.graph.value(URIRef('http://example.net/'), RDFS.label)
rdflib.term.Literal(u'Net')
rdflib.term.Literal('Net')
"""
kws.setdefault("base", self.base)
Expand Down
6 changes: 3 additions & 3 deletions rdflib/plugins/parsers/notation3.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ def join(here: str, there: str) -> str:
We grok IRIs
>>> len(u'Andr\\xe9')
>>> len('Andr\\xe9')
5
>>> join('http://example.org/', u'#Andr\\xe9')
u'http://example.org/#Andr\\xe9'
>>> join('http://example.org/', '#Andr\\xe9')
'http://example.org/#Andr\\xe9'
"""

# assert(here.find("#") < 0), \
Expand Down
8 changes: 4 additions & 4 deletions rdflib/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,28 @@ class ResultRow(Tuple[rdflib.term.Identifier, ...]):
>>> rr=ResultRow({ Variable('a'): URIRef('urn:cake') }, [Variable('a')])
>>> rr[0]
rdflib.term.URIRef(u'urn:cake')
rdflib.term.URIRef('urn:cake')
>>> rr[1]
Traceback (most recent call last):
...
IndexError: tuple index out of range
>>> rr.a
rdflib.term.URIRef(u'urn:cake')
rdflib.term.URIRef('urn:cake')
>>> rr.b
Traceback (most recent call last):
...
AttributeError: b
>>> rr['a']
rdflib.term.URIRef(u'urn:cake')
rdflib.term.URIRef('urn:cake')
>>> rr['b']
Traceback (most recent call last):
...
KeyError: 'b'
>>> rr[Variable('a')]
rdflib.term.URIRef(u'urn:cake')
rdflib.term.URIRef('urn:cake')
.. versionadded:: 4.0
Expand Down
20 changes: 10 additions & 10 deletions rdflib/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
Retrieve some basic facts::
>>> person.identifier
rdflib.term.URIRef(u'http://example.org/person/some1#self')
rdflib.term.URIRef('http://example.org/person/some1#self')
>>> person.value(FOAF.name)
rdflib.term.Literal(u'Some Body')
rdflib.term.Literal('Some Body')
>>> person.value(RDFS.comment)
rdflib.term.Literal(u'Just a Python & RDF hacker.', lang=u'en')
rdflib.term.Literal('Just a Python & RDF hacker.', lang='en')
Resources can be sliced (like graphs, but the subject is fixed)::
Expand All @@ -82,21 +82,21 @@
Resources as unicode are represented by their identifiers as unicode::
>>> %(unicode)s(person) #doctest: +SKIP
u'Resource(http://example.org/person/some1#self'
'Resource(http://example.org/person/some1#self'
Resource references are also Resources, so you can easily get e.g. a qname
for the type of a resource, like::
>>> person.value(RDF.type).qname()
u'foaf:Person'
'foaf:Person'
Or for the predicates of a resource::
>>> sorted(
... p.qname() for p in person.predicates()
... ) #doctest: +NORMALIZE_WHITESPACE +SKIP
[u'foaf:depiction', u'foaf:homepage',
u'foaf:name', u'rdf:type', u'rdfs:comment']
['foaf:depiction', 'foaf:homepage',
'foaf:name', 'rdf:type', 'rdfs:comment']
Follow relations and get more data from their Resources as well::
Expand Down Expand Up @@ -172,18 +172,18 @@
>>> subclasses = list(artifact.transitive_subjects(RDFS.subClassOf))
>>> [c.qname() for c in subclasses]
[u'v:Artifact', u'v:Document', u'v:Paper']
['v:Artifact', 'v:Document', 'v:Paper']
and superclasses from the last subclass::
>>> [c.qname() for c in subclasses[-1].transitive_objects(RDFS.subClassOf)]
[u'v:Paper', u'v:Document', u'v:Artifact']
['v:Paper', 'v:Document', 'v:Artifact']
Get items from the Choice::
>>> choice = Resource(graph, URIRef("http://example.org/def/v#Choice"))
>>> [it.qname() for it in choice.value(OWL.oneOf).items()]
[u'v:One', u'v:Other']
['v:One', 'v:Other']
On add, other resources are auto-unboxed:
>>> paper = Resource(graph, URIRef("http://example.org/def/v#Paper"))
Expand Down
3 changes: 1 addition & 2 deletions test/test_misc/test_bnode_ncname.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def is_ncname(value):
>>> assert is_ncname('') == False
>>> assert is_ncname('999') == False
>>> assert is_ncname('x') == True
>>> assert is_ncname(u'x') == True
>>> assert is_ncname(u'Michèle') == True
>>> assert is_ncname('Michèle') == True
However, vanilla uuid4s are not necessarily NCNames:
Expand Down

0 comments on commit cc7350f

Please sign in to comment.