jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/508034 )
Change subject: Improve title patterns of WikibasePage extensions ......................................................................
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(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
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): """
pywikibot-commits@lists.wikimedia.org