jenkins-bot submitted this change.
[4.0] Remove Python 2 related code in sparql.py
Change-Id: Ia03b2a25b9e439251d20f4fb647dc3fbfd9337a0
---
M pywikibot/data/sparql.py
M tests/sparql_tests.py
2 files changed, 15 insertions(+), 43 deletions(-)
diff --git a/pywikibot/data/sparql.py b/pywikibot/data/sparql.py
index 3ab573b..5756a7f 100644
--- a/pywikibot/data/sparql.py
+++ b/pywikibot/data/sparql.py
@@ -1,32 +1,27 @@
# -*- coding: utf-8 -*-
"""SPARQL Query interface."""
#
-# (C) Pywikibot team, 2016-2019
+# (C) Pywikibot team, 2016-2020
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, division, unicode_literals
import json
+from urllib.parse import quote
from requests.exceptions import Timeout
from pywikibot import config, warning, Site, sleep
from pywikibot.comms import http
-from pywikibot.tools import UnicodeMixin, PY2, py2_encode_utf_8
from pywikibot.exceptions import Error, TimeoutError
-if not PY2:
- from urllib.parse import quote
-else:
- from urllib2 import quote
-
DEFAULT_HEADERS = {'cache-control': 'no-cache',
'Accept': 'application/sparql-results+json'}
-class SparqlQuery(object):
+class SparqlQuery:
"""
SPARQL Query class.
@@ -196,27 +191,23 @@
return result_type()
-class SparqlNode(UnicodeMixin):
+class SparqlNode:
"""Base class for SPARQL nodes."""
def __init__(self, value):
"""Create a SparqlNode."""
self.value = value
- def __unicode__(self):
+ def __str__(self):
return self.value
class URI(SparqlNode):
"""Representation of URI result type."""
- def __init__(self, data, entity_url, **kwargs):
- """
- Create URI object.
-
- @type data: dict
- """
- super(URI, self).__init__(data.get('value'))
+ def __init__(self, data: dict, entity_url, **kwargs):
+ """Create URI object."""
+ super().__init__(data.get('value'))
self.entity_url = entity_url
def getID(self):
@@ -231,7 +222,6 @@
else:
return None
- @py2_encode_utf_8
def __repr__(self):
return '<' + self.value + '>'
@@ -239,17 +229,12 @@
class Literal(SparqlNode):
"""Representation of RDF literal result type."""
- def __init__(self, data, **kwargs):
- """
- Create Literal object.
-
- @type data: dict
- """
- super(Literal, self).__init__(data.get('value'))
+ def __init__(self, data: dict, **kwargs):
+ """Create Literal object."""
+ super().__init__(data.get('value'))
self.type = data.get('datatype')
self.language = data.get('xml:lang')
- @py2_encode_utf_8
def __repr__(self):
if self.type:
return self.value + '^^' + self.type
@@ -261,15 +246,10 @@
class Bnode(SparqlNode):
"""Representation of blank node."""
- def __init__(self, data, **kwargs):
- """
- Create Bnode.
+ def __init__(self, data: dict, **kwargs):
+ """Create Bnode."""
+ super().__init__(data.get('value'))
- @type data: dict
- """
- super(Bnode, self).__init__(data.get('value'))
-
- @py2_encode_utf_8
def __repr__(self):
return '_:' + self.value
diff --git a/tests/sparql_tests.py b/tests/sparql_tests.py
index d418c20..05bd439 100644
--- a/tests/sparql_tests.py
+++ b/tests/sparql_tests.py
@@ -1,14 +1,11 @@
# -*- coding: utf-8 -*-
"""Test cases for the SPARQL API."""
#
-# (C) Pywikibot team, 2016-2019
+# (C) Pywikibot team, 2016-2020
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import pywikibot.data.sparql as sparql
-from pywikibot.tools import UnicodeType
from tests.aspects import unittest, TestCase, WikidataTestCase
from tests import patch
@@ -192,11 +189,6 @@
"""__str__ should return type str."""
self.assertIsInstance(self.object_under_test.__str__(), str)
- def test__unicode__returnsUnicodeType(self):
- """__unicode__ should return type unicode."""
- self.assertIsInstance(self.object_under_test.__unicode__(),
- UnicodeType)
-
class LiteralTests(Shared.SparqlNodeTests):
"""Tests for sparql.Literal."""
To view, visit change 610801. To unsubscribe, or for help writing mail filters, visit settings.