jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
Improve title patterns of WikibasePage extensions

Having ^ at the beginning of a pattern a text is
re.match'd against is pointless. Without ^$,
users can use the patterns for arbitrary string
matching (though we need to refactor the -1 title
handling first). Python 3.4 has a dedicated function
for matching without ^ and $ (re.fullmatch) but
we are still Python 2.7 compatible.

Change-Id: Id0a9b2fc74bd27873f100294c20d1aa6b587fe20
---
M pywikibot/page.py
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 0c3f1d2..c78f962 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4107,7 +4107,8 @@
if not hasattr(cls, 'title_pattern'):
return True

- return bool(re.match(cls.title_pattern, entity_id))
+ # todo: use re.fullmatch when Python 3.4+ required
+ return bool(re.match(cls.title_pattern + '$', entity_id))

@property
def latest_revision_id(self):
@@ -4340,7 +4341,7 @@

_cache_attrs = WikibasePage._cache_attrs + ('sitelinks',)
entity_type = 'item'
- title_pattern = r'^(Q[1-9]\d*|-1)$'
+ title_pattern = r'(Q[1-9]\d*|-1)'

def __init__(self, site, title=None, ns=None):
"""
@@ -4795,7 +4796,7 @@

_cache_attrs = WikibasePage._cache_attrs + ('_type',)
entity_type = 'property'
- title_pattern = r'^(P[1-9]\d*|-1)$'
+ title_pattern = r'(P[1-9]\d*|-1)'

def __init__(self, source, title=None, datatype=None):
"""

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id0a9b2fc74bd27873f100294c20d1aa6b587fe20
Gerrit-Change-Number: 508034
Gerrit-PatchSet: 2
Gerrit-Owner: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Dvorapa <dvorapa@seznam.cz>