jenkins-bot submitted this change.

View Change

Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
[IMPR] Avoid backslash in repr string of WikibaseEntity

currently a wikibase repr string may look like
Claim(DataSite("wikidata", "wikidata"), \'P7829\') within a string.
Now use only one sort of quotion mark.

Change-Id: I3ee5222043ba7f2a6e11c4e9c372ba61c1c0f2d0
---
M pywikibot/__init__.py
M pywikibot/site/_basesite.py
M tests/site_tests.py
3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 1d08b81..2889125 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -160,7 +160,7 @@
>>> site_1 is site_2
True
>>> site_1
- APISite("fr", "wikisource")
+ APISite('fr', 'wikisource')

:class:`APISite<pywikibot.site._apisite.APISite>` is the default
interface. Refer :py:obj:`pywikibot.site` for other interface types.
diff --git a/pywikibot/site/_basesite.py b/pywikibot/site/_basesite.py
index 2eaa581..570f23c 100644
--- a/pywikibot/site/_basesite.py
+++ b/pywikibot/site/_basesite.py
@@ -228,7 +228,7 @@

def __repr__(self) -> str:
"""Return internal representation."""
- return f'{self.__class__.__name__}("{self.code}", "{self.family}")'
+ return f'{type(self).__name__}({self.code!r}, {self.family.name!r})'

def __hash__(self):
"""Return hash value of instance."""
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 0016b2c..83f0c7d 100755
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -72,8 +72,10 @@
def test_repr(self):
"""Test __repr__."""
code = self.site.family.obsolete.get(self.code) or self.code
- expect = f'Site("{code}", "{self.family}")'
- self.assertTrue(repr(self.site).endswith(expect))
+ expect = f"Site('{code}', '{self.family}')"
+ reprs = repr(self.site)
+ self.assertTrue(reprs.endswith(expect),
+ f'\n{reprs} does not end with {expect}')

def test_constructors(self):
"""Test cases for site constructors."""

To view, visit change 1051093. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3ee5222043ba7f2a6e11c4e9c372ba61c1c0f2d0
Gerrit-Change-Number: 1051093
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot