Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1074403?usp=email )
Change subject: [IMPR] Show a warning message for a deleted or unknown claim type
......................................................................
[IMPR] Show a warning message for a deleted or unknown claim type
Show this warning once and only if WbUnknown.toWikibase() is called.
Also update tests-
Bug: T374676
Change-Id: I56400c8f24390608c225ea953f406d6cbd329ff7
---
M pywikibot/_wbtypes.py
M pywikibot/page/_wikibase.py
M tests/wikibase_tests.py
3 files changed, 24 insertions(+), 17 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/_wbtypes.py b/pywikibot/_wbtypes.py
index 4764cfa..66374df 100644
--- a/pywikibot/_wbtypes.py
+++ b/pywikibot/_wbtypes.py
@@ -1151,8 +1151,7 @@
class WbUnknown(WbRepresentation):
- """
- A Wikibase representation for unknown data type.
+ """A Wikibase representation for unknown data type.
This will prevent the bot from breaking completely when a new type
is introduced.
@@ -1160,24 +1159,34 @@
This data type is just a json container
.. versionadded:: 3.0
+ .. versionchanged:: 9.4
+ *warning* parameter was added
"""
_items = ('json',)
- def __init__(self, json: dict[str, Any]) -> None:
+ def __init__(self, json: dict[str, Any], warning: str = '') -> None:
"""
Create a new WbUnknown object.
:param json: Wikibase JSON
+ :param warning: a warning message which is shown once if
+ :meth:`toWikibase` is called
"""
self.json = json
+ self.warning = warning
def toWikibase(self) -> dict[str, Any]:
- """
- Return the JSON object for the Wikibase API.
+ """Return the JSON object for the Wikibase API.
+
+ .. versionchanged:: 9.4
+ a waning message given by the warning attribute is shown once.
:return: Wikibase JSON
"""
+ if self.warning:
+ pywikibot.warning(self.warning)
+ self.warning = ''
return self.json
@classmethod
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 881f3d3..65c2181 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -1777,19 +1777,19 @@
except NoWikibaseEntityError:
claim_type = None
- claim.target = None
+ msg = None
if not claim_type:
- pywikibot.warning(f'{claim.id} does not exist.')
+ msg = '{claim.id} does not exist.'
elif claim.type in cls.types:
# The default covers string, url types
claim.target = cls.TARGET_CONVERTER.get(
claim.type, lambda value, site: value)(value, site)
else:
- pywikibot.warning(
- f'{claim.type} datatype is not supported yet.')
+ msg = f'{claim.type} datatype is not supported yet.'
- if claim.target is None:
+ if msg is not None:
claim.target = pywikibot.WbUnknown.fromWikibase(value)
+ claim.target.warning = msg
if 'rank' in data: # References/Qualifiers don't have ranks
claim.rank = data['rank']
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index a5c3135..0a1f9c2 100755
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -14,7 +14,6 @@
import unittest
from contextlib import suppress
from decimal import Decimal
-from unittest import mock
import pywikibot
from pywikibot import pagegenerators
@@ -1192,12 +1191,11 @@
def test_load_unknown(self):
"""Ensure unknown value is loaded but raises a warning."""
- with mock.patch.object(pywikibot, 'warning', autospec=True) as warn:
- self.wdp.get()
- unknown_value = self.wdp.claims['P99999'][0].getTarget()
- self.assertIsInstance(unknown_value, pywikibot.WbUnknown)
- warn.assert_called_once_with(
- 'foo-unknown-bar datatype is not supported yet.')
+ self.wdp.get()
+ unknown_value = self.wdp.claims['P99999'][0].getTarget()
+ self.assertIsInstance(unknown_value, pywikibot.WbUnknown)
+ self.assertEqual(unknown_value.warning,
+ 'foo-unknown-bar datatype is not supported yet.')
class TestItemPageExtensibility(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1074403?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I56400c8f24390608c225ea953f406d6cbd329ff7
Gerrit-Change-Number: 1074403
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Amire80 <amir.aharoni(a)mail.huji.ac.il>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Matěj Suchánek <matejsuchanek97(a)gmail.com>
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1074562?usp=email )
Change subject: pywikibot.scripts: Remove preload_sites.py
......................................................................
pywikibot.scripts: Remove preload_sites.py
This script mno longer works with the current login implementation.
Bug: T348925
Change-Id: I18ef387df276530b60eb9d07b81685b65fc64e75
---
M docs/faq.rst
M docs/utilities/scripts.rst
M docs/utilities/scripts_ref.rst
M pywikibot/CONTENT.rst
M pywikibot/scripts/__init__.py
D pywikibot/scripts/preload_sites.py
6 files changed, 17 insertions(+), 162 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/docs/faq.rst b/docs/faq.rst
index c422292..483909c 100644
--- a/docs/faq.rst
+++ b/docs/faq.rst
@@ -4,24 +4,21 @@
**How to speed up Pywikibot?**
- 1. The first time you are using Pywikibot for multiple Wikimedia sites you
- can run :py:mod:`preload_sites <pywikibot.scripts.preload_sites>` script
- to preload site info quickly.
- 2. If you need the content, use :py:mod:`PreloadingGenerator
- <pagegenerators.PreloadingGenerator>` with page generators,
- :py:mod:`EntityGenerator <pagegenerators.EntityGenerator>`
- for wikibase entities and :py:mod:`DequePreloadingGenerator
- <pagegenerators.DequePreloadingGenerator>` for a
- :py:mod:`DequeGenerator <tools.collections.DequeGenerator>`.
- 3. If you use :py:mod:`GeneratorFactory
- <pagegenerators.GeneratorFactory>` with your bot and use its
- :py:mod:`getCombinedGenerator
- <pagegenerators.GeneratorFactory.getCombinedGenerator>` method
- you can set ``preload=True`` to preload page content. This is an alternate
- to the ``PreloadingGenerator`` function mentioned above.
- 4. Use :py:mod:`MySQLPageGenerator
- <pagegenerators.MySQLPageGenerator >` if direct DB access is
- available and appropriate. See also: :manpage:`MySQL`
+ * If you need the content, use :py:mod:`PreloadingGenerator
+ <pagegenerators.PreloadingGenerator>` with page generators,
+ :func:`PreloadingEntityGenerator <pagegenerators.PreloadingEntityGenerator>`
+ for wikibase entities and :py:mod:`DequePreloadingGenerator
+ <pagegenerators.DequePreloadingGenerator>` for a
+ :py:mod:`DequeGenerator <tools.collections.DequeGenerator>`.
+ * If you use :py:mod:`GeneratorFactory
+ <pagegenerators.GeneratorFactory>` with your bot and use its
+ :py:mod:`getCombinedGenerator
+ <pagegenerators.GeneratorFactory.getCombinedGenerator>` method
+ you can set ``preload=True`` to preload page content. This is an alternate
+ to the ``PreloadingGenerator`` function mentioned above.
+ * Use :func:`MySQLPageGenerator
+ <pagegenerators.MySQLPageGenerator>` if direct DB access is
+ available and appropriate. See also: :manpage:`MySQL`
**The bot cannot delete pages**
Your account needs delete rights on your wiki. If you have setup another
diff --git a/docs/utilities/scripts.rst b/docs/utilities/scripts.rst
index 474bca9..a55ee54 100644
--- a/docs/utilities/scripts.rst
+++ b/docs/utilities/scripts.rst
@@ -34,13 +34,6 @@
:no-members:
:noindex:
-preload_sites script
-====================
-
-.. automodule:: pywikibot.scripts.preload_sites
- :no-members:
- :noindex:
-
shell script
============
diff --git a/docs/utilities/scripts_ref.rst b/docs/utilities/scripts_ref.rst
index d5acf52..1f796e5 100644
--- a/docs/utilities/scripts_ref.rst
+++ b/docs/utilities/scripts_ref.rst
@@ -30,12 +30,6 @@
.. automodule:: pywikibot.scripts.login
:synopsis: Script to log the bot in to a wiki account
-preload_sites script
-====================
-
-.. automodule:: pywikibot.scripts.preload_sites
- :synopsis: Script that preloads site and user info for all sites of given family
-
shell script
============
diff --git a/pywikibot/CONTENT.rst b/pywikibot/CONTENT.rst
index c1a131e..4f02a96 100644
--- a/pywikibot/CONTENT.rst
+++ b/pywikibot/CONTENT.rst
@@ -158,10 +158,6 @@
+----------------------------+------------------------------------------------------+
| login.py | Script to log the bot in to a wiki account. |
+----------------------------+------------------------------------------------------+
- | preload_sites.py | Preload and cache site information for each |
- | | WikiMedia family within seconds. Useful for bots |
- | | running on multiple sites. |
- +----------------------------+------------------------------------------------------+
| shell.py | Spawns an interactive Python shell with pywikibot |
| | imported |
+----------------------------+------------------------------------------------------+
diff --git a/pywikibot/scripts/__init__.py b/pywikibot/scripts/__init__.py
index fabe48b..73a1e55 100644
--- a/pywikibot/scripts/__init__.py
+++ b/pywikibot/scripts/__init__.py
@@ -1,6 +1,8 @@
"""Folder which holds framework scripts.
.. versionadded:: 7.0
+.. versionremoved:: 9.4
+ ``preload_sites`` script was removed (:phab:`T348925`).
"""
#
# (C) Pywikibot team, 2021-2022
diff --git a/pywikibot/scripts/preload_sites.py b/pywikibot/scripts/preload_sites.py
deleted file mode 100755
index 6bd3b66..0000000
--- a/pywikibot/scripts/preload_sites.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/usr/bin/env python3
-"""Script that preloads site and user info for all sites of given family.
-
-The following parameters are supported:
-
- -worker:<num> The number of parallel tasks to be run. Default is the
- number of processors on the machine
-
-**Usage:**
-
- python pwb.py preload_sites [{<family>}] [-worker:{<num>}]
-
-To force preloading, change the global expiry values to 0:
-
- python pwb.py -API_config_expiry:0 -API_uinfo_expiry:0 \
- preload_sites [{<family>}]
-
-or run the :mod:`cache<scripts.maintenance.cache>` script previeously:
-
- python pwb.py cache -delete
-
-.. versionchanged:: 7.4
- script was moved to the framework scripts folder.
-"""
-#
-# (C) Pywikibot team, 2021-2024
-#
-# Distributed under the terms of the MIT license.
-#
-from __future__ import annotations
-
-from concurrent.futures import ThreadPoolExecutor, wait
-from datetime import datetime
-
-import pywikibot
-from pywikibot.backports import removeprefix
-from pywikibot.family import Family
-
-
-try: # Python 3.13
- from os import process_cpu_count # type: ignore[attr-defined]
-except ImportError:
- from os import cpu_count as process_cpu_count
-
-
-#: supported families by this script
-families_list = [
- 'wikibooks',
- 'wikinews',
- 'wikipedia',
- 'wikiquote',
- 'wikisource',
- 'wikiversity',
- 'wikivoyage',
- 'wiktionary',
-]
-
-# Ignore sites from preloading
-# example: {'wikiversity': ['beta'], }
-exceptions: dict[str, list[str]] = {
-}
-
-
-def preload_family(family: str, executor: ThreadPoolExecutor) -> None:
- """Preload all sites of a single family file.
-
- .. versionchanged:: 9.2
- use a separate worker thread for each site.
- """
-
- def create_page(code, family):
- """Preload siteinfo and userinfo."""
- site = pywikibot.Site(code, family)
- pywikibot.Page(site, 'Main Page')
-
- msg = 'Preloading sites of {} family{}'
- pywikibot.info(msg.format(family, '...'))
-
- codes = Family.load(family).codes
- for code in exceptions.get(family, []):
- if code in codes:
- codes.remove(code)
-
- obsolete = Family.load(family).obsolete
-
- futures = set()
- for code in codes:
- if code not in obsolete:
- futures.add(executor.submit(create_page, code, family))
- wait(futures)
- pywikibot.info(msg.format(family, ' completed.'))
-
-
-def preload_families(families: list[str] | set[str],
- worker: int | None) -> None:
- """Preload all sites of all given family files.
-
- .. versionchanged:: 7.3
- Default of worker is calculated like for Python 3.8 but preserves
- at least one worker for each element in families_list for better
- performance.
- """
- start = datetime.now()
- if worker is None:
- # Python 3.13 default
- worker = min(32, (process_cpu_count() or 1) + 4)
- # to allow adding futures in preload_family the workers must be one
- # more than families are handled
- worker = max(len(families) * 2, worker)
- pywikibot.info(
- f'Using {worker} workers to process {len(families)} families')
- with ThreadPoolExecutor(worker) as executor:
- futures = {executor.submit(preload_family, family, executor)
- for family in families}
- wait(futures)
- pywikibot.info(f'Loading time used: {datetime.now() - start}')
-
-
-if __name__ == '__main__':
- fam = set()
- worker = None
- for arg in pywikibot.handle_args():
- if arg in families_list:
- fam.add(arg)
- elif arg.startswith('-worker:'):
- worker = int(removeprefix(arg, '-worker:'))
- preload_families(fam or families_list, worker)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1074562?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I18ef387df276530b60eb9d07b81685b65fc64e75
Gerrit-Change-Number: 1074562
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1073861?usp=email )
Change subject: [IMPR] add User.renamed_target() method
......................................................................
[IMPR] add User.renamed_target() method
- User.renamed_target() gives the User object for a user was renamed to.
- Also add NoRenameTargetError exception which is raised if the source
user wasn't renamed.
- update documentation
Change-Id: If4affa04fb41dfddfa90fdcbe65f39b89c585426
---
M pywikibot/exceptions.py
M pywikibot/page/_basepage.py
M pywikibot/page/_user.py
3 files changed, 61 insertions(+), 7 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 9104e7b..ec403e2 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -22,6 +22,7 @@
| +-- IsRedirectPageError
| +-- NoMoveTargetError
| +-- NoPageError
+ | +-- NoRenameTargetError
| +-- NotEmailableError
| +-- PageLoadRelatedError
| | +-- InconsistentTitleError
@@ -104,6 +105,7 @@
- InvalidPageError: Page is invalid e.g. without history
- NotEmailableError: The target user has disabled email
- NoMoveTargetError: An expected move target page does not exist
+ - NoRenameTargetError: An expected rename target user does not exist
PageLoadRelatedError: any exception which happens while loading a Page.
- InconsistentTitleError: Page receives a title inconsistent with query
@@ -371,6 +373,16 @@
message = 'Move target page of {} not found.'
+class NoRenameTargetError(PageRelatedError):
+
+ """Expected rename target user not found.
+
+ .. versionadded:: 9.4
+ """
+
+ message = 'Rename target user of {} not found.'
+
+
class PageLoadRelatedError(PageRelatedError):
"""Loading the contents of a Page object has failed."""
diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index beaf75e..1d675fe 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -1826,8 +1826,10 @@
.. versionadded:: 9.3
*ignore_section* parameter
- .. seealso:: :meth:`Site.getredirtarget()
- <pywikibot.site._apisite.APISite.getredirtarget>`
+ .. seealso::
+ * :meth:`Site.getredirtarget()
+ <pywikibot.site._apisite.APISite.getredirtarget>`
+ * :meth:`moved_target`
:param ignore_section: do not include section to the target even
the link has one
@@ -1842,15 +1844,15 @@
"""
return self.site.getredirtarget(self, ignore_section=ignore_section)
- def moved_target(self):
- """
- Return a Page object for the target this Page was moved to.
+ def moved_target(self) -> pywikibot.page.Page:
+ """Return a Page object for the target this Page was moved to.
If this page was not moved, it will raise a NoMoveTargetError.
This method also works if the source was already deleted.
- :rtype: pywikibot.page.Page
- :raises pywikibot.exceptions.NoMoveTargetError: page was not moved
+ .. seealso:: :meth:`getRedirectTarget`
+
+ :raises NoMoveTargetError: page was not moved
"""
gen = iter(self.site.logevents(logtype='move', page=self, total=1))
try:
diff --git a/pywikibot/page/_user.py b/pywikibot/page/_user.py
index 8047772..01ed5e6 100644
--- a/pywikibot/page/_user.py
+++ b/pywikibot/page/_user.py
@@ -11,6 +11,7 @@
from pywikibot.exceptions import (
APIError,
AutoblockUserError,
+ NoRenameTargetError,
NotEmailableError,
UserRightsError,
)
@@ -451,3 +452,42 @@
:phab:`T57401#2216861` and :phab:`T120753#1863894`.
"""
return self.isRegistered() and 'bot' not in self.groups()
+
+ def renamed_target(self) -> User:
+ """Return a User object for the target this user was renamed to.
+
+ If this user was not renamed, it will raise a
+ :exc:`NoRenameTargetError`.
+
+ **Usage:**
+
+ >>> site = pywikibot.Site('wikipedia:de')
+ >>> user = pywikibot.User(site, 'Foo')
+ >>> user.isRegistered()
+ False
+ >>> target = user.renamed_target()
+ >>> target.isRegistered()
+ True
+ >>> target.title(with_ns=False)
+ 'Foo~dewiki'
+ >>> target.renamed_target()
+ Traceback (most recent call last):
+ ...
+ pywikibot.exceptions.NoRenameTargetError: Rename target user ...
+
+ .. seealso::
+ * :meth:`BasePage.moved_target`
+ * :meth:`BasePage.getRedirectTarget`
+
+ .. versionadded:: 9.4
+
+ :raises NoRenameTargetError: user was not renamed
+ """
+ gen = iter(self.site.logevents(logtype='renameuser',
+ page=self, total=1))
+ try:
+ renamed = next(gen)
+ except StopIteration:
+ raise NoRenameTargetError(self)
+
+ return User(self.site, renamed.params['newuser'])
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1073861?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If4affa04fb41dfddfa90fdcbe65f39b89c585426
Gerrit-Change-Number: 1073861
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Mirji <mirji(a)dismail.de>
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1073778?usp=email )
Change subject: [IMPR] Check whether Claim exists within Claim.fromJSON() method
......................................................................
[IMPR] Check whether Claim exists within Claim.fromJSON() method
- If a Claim type is not given to the initializer, the type is fetched
from wikibase. This can fail if it does not exist. Try to get the
type and if NoWikibaseEntityError write a warning instead raising
a KeyError
- add a new exists() method to Property class
- raise NoWikibaseEntityError in Property.type property instead of
KeyError
Bug: T374681
Change-Id: Id9047cfe688c9a13c9ccc4c4ee1aebe5628abe4c
---
M pywikibot/page/_wikibase.py
1 file changed, 47 insertions(+), 10 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 5ebe25d..881f3d3 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -1428,11 +1428,34 @@
if datatype:
self._type = datatype
+ def exists(self):
+ """Determine if the property exists in the data repository.
+
+ .. versionadded:: 9.4
+ """
+ try:
+ self._type = self.repo.getPropertyType(self)
+ except KeyError:
+ return False
+ return True
+
@property
@cached
def type(self) -> str:
- """Return the type of this property."""
- return self.repo.getPropertyType(self)
+ """Return the type of this property.
+
+ .. versionchanged:: 9.4
+ raises :exc:`NoWikibaseEntityError` if property does not
+ exist.
+
+ :raises NoWikibaseEntityError: property does not exist
+ """
+ try:
+ prop_type = self.repo.getPropertyType(self)
+ except KeyError as e:
+ raise NoWikibaseEntityError(e)
+
+ return prop_type
def getID(self, numeric: bool = False):
"""
@@ -1727,14 +1750,14 @@
return copy
@classmethod
- def fromJSON(cls, site, data):
- """
- Create a claim object from JSON returned in the API call.
+ def fromJSON(cls, site, data: dict[str, Any]) -> Claim:
+ """Create a claim object from JSON returned in the API call.
+
+ .. versionchanged:: 9.4
+ print a warning if the Claim.type is not given and missing in
+ the wikibase.
:param data: JSON containing claim data
- :type data: dict
-
- :rtype: pywikibot.page.Claim
"""
claim_repo = site.get_repo_for_entity_type('property')
claim = cls(claim_repo, data['mainsnak']['property'],
@@ -1743,17 +1766,31 @@
claim.snak = data['id']
elif 'hash' in data:
claim.hash = data['hash']
+
claim.snaktype = data['mainsnak']['snaktype']
if claim.getSnakType() == 'value':
value = data['mainsnak']['datavalue']['value']
- # The default covers string, url types
- if claim.type in cls.types:
+
+ # note: claim.type could be set during claim initialization
+ try:
+ claim_type = claim.type
+ except NoWikibaseEntityError:
+ claim_type = None
+
+ claim.target = None
+ if not claim_type:
+ pywikibot.warning(f'{claim.id} does not exist.')
+ elif claim.type in cls.types:
+ # The default covers string, url types
claim.target = cls.TARGET_CONVERTER.get(
claim.type, lambda value, site: value)(value, site)
else:
pywikibot.warning(
f'{claim.type} datatype is not supported yet.')
+
+ if claim.target is None:
claim.target = pywikibot.WbUnknown.fromWikibase(value)
+
if 'rank' in data: # References/Qualifiers don't have ranks
claim.rank = data['rank']
if 'references' in data:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1073778?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Id9047cfe688c9a13c9ccc4c4ee1aebe5628abe4c
Gerrit-Change-Number: 1073778
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Lokal Profil <andre.costa(a)wikimedia.se>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Amire80 <amir.aharoni(a)mail.huji.ac.il>
Gerrit-CC: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1074554?usp=email )
Change subject: [doc] update ROADMAP.rst and documentation
......................................................................
[doc] update ROADMAP.rst and documentation
Change-Id: Ic94013d7a403aa1651567527a4d194b7650f17f1
---
M ROADMAP.rst
M pywikibot/page/_wikibase.py
2 files changed, 15 insertions(+), 9 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/ROADMAP.rst b/ROADMAP.rst
index b1e6268..4c2f745 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,6 +1,7 @@
Current Release Changes
=======================
+* Add :meth:`title()<pywikibot.MediaInfo.title>` method to :class:`pywikibot.MediaInfo` (:phab:`T366424`)
* Add tags to the wikibase functions (:phab:`T372513`)
* :func:`diff.get_close_matches_ratio()` function was added
* Initialize super classes of :exc:`EditReplacementError` (:phab:`T212740`)
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 5ebe25d..1e76780 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -510,22 +510,27 @@
# reloading files without MediaInfo will fail.
return super().get()
- def getID(self, numeric: bool = False):
- """
- Get the entity identifier.
+ def getID(self, numeric: bool = False) -> str | int:
+ """Get the entity identifier.
+
+ .. seealso:: :meth:`title`
:param numeric: Strip the first letter and return an int
- :raise NoWikibaseEntityError: if this entity is associated with
- a non-existing file
+ :raises NoWikibaseEntityError: if this entity is associated with
+ a non-existing file
"""
self._assert_has_id()
return super().getID(numeric=numeric)
- def title(self):
- """
- Return ID as title of the MediaInfo.
+ def title(self) -> str:
+ """Return ID as title of the MediaInfo.
- :return: str: the entity identifier
+ .. versionadded:: 9.4
+ .. seealso:: :meth:`getID`
+
+ :raises NoWikibaseEntityError: if this entity is associated with
+ a non-existing file
+ :return: the entity identifier
"""
return self.getID()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1074554?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic94013d7a403aa1651567527a4d194b7650f17f1
Gerrit-Change-Number: 1074554
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot