jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/729490 )
Change subject: [doc] Add version hints to tools
......................................................................
[doc] Add version hints to tools
Change-Id: I7f7924cfeec646e2684e5719ed162b7c22a57554
---
M pywikibot/tools/__init__.py
M pywikibot/tools/_deprecate.py
2 files changed, 108 insertions(+), 21 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 96bd494..a988b10 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -71,6 +71,9 @@
def is_ip_address(value: str) -> bool:
"""Check if a value is a valid IPv4 or IPv6 address.
+ .. versionadded:: 6.1
+ Was renamed from ``is_IP()``.
+
:param value: value to check
"""
with suppress(ValueError):
@@ -83,7 +86,11 @@
def has_module(module, version=None):
"""Check if a module can be imported.
- *New in version 3.0.*
+ .. versionadded:: 3.0
+
+ .. versionchanged:: 6.1
+ Dependency of distutils was dropped because the package will be
+ removed with Python 3.12.
"""
try:
m = import_module(module)
@@ -120,6 +127,8 @@
return cls._bar
Foo.bar gives 'baz'.
+
+ .. versionadded:: 3.0
"""
def __init__(self, cls_method):
@@ -139,7 +148,7 @@
Those suppressed warnings that do not match the parameters will be raised
shown upon exit.
- *New in vesion 3.0.*
+ .. versionadded:: 3.0
"""
def __init__(self, message='', category=Warning, filename=''):
@@ -193,7 +202,10 @@
# From http://python3porting.com/preparing.html
class ComparableMixin:
- """Mixin class to allow comparing to other objects which are comparable."""
+ """Mixin class to allow comparing to other objects which are comparable.
+
+ .. versionadded:: 3.0
+ """
def __lt__(self, other):
"""Compare if self is less than other."""
@@ -255,7 +267,7 @@
>>> list(data)
[]
- *New in version 6.1.*
+ .. versionadded:: 6.1
"""
def __init__(self, keyattr: str):
@@ -336,6 +348,8 @@
Return a string with the first character uncapitalized.
Empty strings are supported. The original string is not changed.
+
+ .. versionadded:: 3.0
"""
return string[:1].lower() + string[1:]
@@ -346,6 +360,8 @@
Empty strings are supported. The original string is not changed.
+ .. versionadded:: 3.0
+
:note: MediaWiki doesn't capitalize some characters the same way as Python.
This function tries to be close to MediaWiki's capitalize function in
title.php. See T179115 and T200357.
@@ -355,7 +371,10 @@
def normalize_username(username) -> Optional[str]:
- """Normalize the username."""
+ """Normalize the username.
+
+ .. versionadded:: 3.0
+ """
if not username:
return None
username = re.sub('[_ ]+', ' ', username).strip()
@@ -368,11 +387,9 @@
This Version provides propreties of vendor package 20.4 shipped with
setuptools 49.4.0.
- """
- def __init__(self, version):
- """Add additional properties of not provided by base class."""
- super().__init__(version)
+ .. versionadded:: 6.4
+ """
def __getattr__(self, name):
"""Provides propreties of vendor package 20.4."""
@@ -415,6 +432,12 @@
< 1.35-rc-1 < 1.35-rc.2 < 1.35
Any other suffixes are considered invalid.
+
+ .. versionadded:: 3.0
+
+ .. versionchanged:: 6.1
+ Dependency of distutils was dropped because the package will be
+ removed with Python 3.12.
"""
MEDIAWIKI_VERSION = re.compile(
@@ -521,7 +544,7 @@
>>> lock.locked()
False
- *New in version 6.2*
+ .. versionadded:: 6.2
"""
def __init__(self, *args, **kwargs):
@@ -584,6 +607,7 @@
>>> data
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
+ ..versionadded:: 3.0
"""
def __init__(self, group=None, target=None, name='GeneratorThread',
@@ -796,6 +820,20 @@
>>> list(intersect_generators(*iterables, allow_duplicates=True))
['m', 'i', 's', 's', 'i']
+
+ .. versionadded:: 3.0
+
+ .. versionchanged:: 5.0
+ Avoid duplicates (T263947).
+
+ .. versionchanged:: 6.4
+ ``genlist`` was renamed to ``iterables``; consecutive iterables
+ are to be used as iterables parameters or '*' to unpack a list
+
+ .. deprecated:: 6.4
+ ``allow_duplicates`` as positional argument,
+ ``iterables`` as list type
+
:param iterables: page generators
:param allow_duplicates: optional keyword argument to allow duplicates
if present in all generators
@@ -901,7 +939,10 @@
>>> tuple(roundrobin_generators('ABC', range(5)))
('A', 0, 'B', 1, 'C', 2, 3, 4)
- *New in version 3.0.*
+ .. versionadded:: 3.0
+ .. versionchanged:: 6.4
+ A sentinel variable is used to determine the end of an iterable
+ instead of None.
:param iterables: any iterable to combine in roundrobin way
:type iterables: iterable
@@ -942,6 +983,8 @@
Note: This is not thread safe.
+ .. versionadded: 3.0
+
:param iterable: the source iterable
:type iterable: collections.abc.Iterable
:param container: storage of seen items
@@ -978,7 +1021,10 @@
class CombinedError(KeyError, IndexError):
- """An error that gets caught by both KeyError and IndexError."""
+ """An error that gets caught by both KeyError and IndexError.
+
+ .. versionadded:: 3.0
+ """
class EmptyDefault(str, Mapping):
@@ -992,6 +1038,10 @@
Accessing a value via __getitem__ will result in a combined KeyError and
IndexError.
+
+ .. versionadded:: 3.0
+ .. versionchanged:: 6.2
+ ``empty_iterator()`` was removed in favour of ``iter()``.
"""
def __init__(self):
@@ -1017,29 +1067,45 @@
When '_own_desc' is defined it'll also issue a deprecation warning using
issue_deprecation_warning('Calling ' + _own_desc, 'it directly').
+
+ .. versionadded:: 3.0
+ .. deprecated:: 6.2
"""
def __call__(self):
"""Do nothing and just return itself."""
issue_deprecation_warning('Referencing this attribute like a function',
- 'it directly', since='20210420')
+ 'it directly', since='6.2')
return self
class SelfCallDict(SelfCallMixin, dict):
- """Dict with SelfCallMixin."""
+ """Dict with SelfCallMixin.
+
+ .. versionadded:: 3.0
+ .. deprecated:: 6.2
+ """
class SelfCallString(SelfCallMixin, str):
- """String with SelfCallMixin."""
+ """String with SelfCallMixin.
+
+ .. versionadded:: 3.0
+ .. deprecated:: 6.2
+ """
class DequeGenerator(Iterator, collections.deque):
- """A generator that allows items to be added during generating."""
+ """A generator that allows items to be added during generating.
+
+ .. versionadded:: 3.0
+ .. versionchanged:: 6.1
+ Provide a representation string.
+ """
def __next__(self):
"""Iterator method."""
@@ -1067,6 +1133,8 @@
The compression is either selected via the magic number or file ending.
+ .. versionadded:: 3.0
+
:param filename: The filename.
:type filename: str
:param use_extension: Use the file extension instead of the magic number
@@ -1168,6 +1236,8 @@
The positional arguments are the dictionaries to be merged. It is also
possible to define an additional dict using the keyword arguments.
+
+ .. versionadded: 3.0
"""
args = list(args) + [dict(kwargs)]
conflicts = set()
@@ -1185,6 +1255,8 @@
def file_mode_checker(filename: str, mode=0o600, quiet=False, create=False):
"""Check file mode and update it, if needed.
+ .. versionadded: 3.0
+
:param filename: filename path
:param mode: requested file mode
:type mode: int
@@ -1215,6 +1287,8 @@
Result is expressed as hexdigest().
+ .. versionadded: 3.0
+
:param filename: filename path
:param sha: hashing function among the following in hashlib:
md5(), sha1(), sha224(), sha256(), sha384(), and sha512()
diff --git a/pywikibot/tools/_deprecate.py b/pywikibot/tools/_deprecate.py
index 829b24c..a043e5d 100644
--- a/pywikibot/tools/_deprecate.py
+++ b/pywikibot/tools/_deprecate.py
@@ -15,7 +15,8 @@
only one arg, and that arg be a callable, as it will be detected as
a deprecator without any arguments.
-*Changed in version 6.4:* deprecation decorators moved to _deprecate module
+.. versionchanged 6.4:
+ deprecation decorators moved to _deprecate module
"""
#
# (C) Pywikibot team, 2008-2021
@@ -37,7 +38,10 @@
class _NotImplementedWarning(RuntimeWarning):
- """Feature that is no longer implemented."""
+ """Feature that is no longer implemented.
+
+ .. versionadded:: 3.0
+ """
def add_decorated_full_name(obj, stacklevel=1):
@@ -66,7 +70,10 @@
def manage_wrapping(wrapper, obj):
- """Add attributes to wrapper and wrapped functions."""
+ """Add attributes to wrapper and wrapped functions.
+
+ .. versionadded:: 3.0
+ """
wrapper.__doc__ = obj.__doc__
wrapper.__name__ = obj.__name__
wrapper.__module__ = obj.__module__
@@ -91,7 +98,10 @@
def get_wrapper_depth(wrapper):
- """Return depth of wrapper function."""
+ """Return depth of wrapper function.
+
+ .. versionadded:: 3.0
+ """
return wrapper.__wrapped__.__wrappers__ + (1 - wrapper.__depth__)
@@ -155,7 +165,10 @@
def _build_msg_string(instead, since):
- """Build a deprecation warning message format string."""
+ """Build a deprecation warning message format string.
+
+ .. versionadded:: 3.0
+ """
if not since:
since = ''
elif '.' in since:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/729490
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I7f7924cfeec646e2684e5719ed162b7c22a57554
Gerrit-Change-Number: 729490
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/729475 )
Change subject: [bugfix] Require sphinx >= 4.1
......................................................................
[bugfix] Require sphinx >= 4.1
Bug: T292921
Change-Id: I29aee1719dd2fb8cd81036a1344c167ea0afd9d9
---
M docs/conf.py
M docs/requirements-py3.txt
2 files changed, 2 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/conf.py b/docs/conf.py
index d4430c2..d72fff1 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -46,7 +46,7 @@
# If your documentation needs a minimal Sphinx version, state it here.
#
-needs_sphinx = '1.8'
+needs_sphinx = '4.1'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
diff --git a/docs/requirements-py3.txt b/docs/requirements-py3.txt
index f6022b4..3a80334 100644
--- a/docs/requirements-py3.txt
+++ b/docs/requirements-py3.txt
@@ -1,4 +1,4 @@
# This is a PIP requirements file for building Sphinx documentation of pywikibot
# requirements.txt is also needed
-sphinx > 3.5.0, != 4.0.0
\ No newline at end of file
+sphinx >= 4.1.0
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/729475
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I29aee1719dd2fb8cd81036a1344c167ea0afd9d9
Gerrit-Change-Number: 729475
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/729142 )
Change subject: [doc] Update ROADMAP.rst and CHANGELOG.md
......................................................................
[doc] Update ROADMAP.rst and CHANGELOG.md
Change-Id: I88d004ece927d75e9f6f7151b5b8da745938ca71
---
M ROADMAP.rst
M pywikibot/exceptions.py
M scripts/CHANGELOG.md
3 files changed, 47 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index 37e0783..eba2565 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,6 +1,14 @@
Current release changes
^^^^^^^^^^^^^^^^^^^^^^^
+Improvements and Bugfixes
+-------------------------
+
+* Adjust groupsize within pagegenerators.PreloadingGenerator (T291770)
+* New "maxlimit" property was added to APISite (T291770)
+
+
+
Breaking changes
----------------
@@ -10,6 +18,13 @@
Code cleanups
-------------
+* Outdated parameter names has been dropped
+* Deprecated pywikibot.Error exception were removed in favour of pywikibot.exceptions.Error classes (T280227)
+* Deprecated exception identifiers were removed (T280227)
+* Deprecated date.FormatDate class was removed in favour of date.format_date function
+* language_by_size property of wowwiki Family was removed in favour of codes attribute
+* availableOptions was removed in favour of available_options
+* config2 was removed in favour of config
* tools.RotatingFileHandler was removed in favour of logging.handlers.RotatingFileHandler
* tools.DotReadableDict, tools.LazyRegex and tools.DeprecatedRegex classes were removed
* tools.frozenmap was removed in favour of types.MappingProxyType
@@ -29,8 +44,4 @@
* 6.4.0: Pywikibot `began using semantic versioning
<https://www.mediawiki.org/wiki/Manual:Pywikibot/Development/Guidelines#Depr…>`_,
all deprecated code will be removed in Pywikibot version 7.0.0.
-* 6.2.0: Bot's availableOptions will be removed in favour of available_options
-* 6.2.0: Usage of pywikibot.config2 is deprecated and will be dropped
-* 6.2.0: Exceptions must be imported from exceptions namespace (T280227)
-* 6.2.0: Deprecated exception identifiers will be removed (T280227)
* 5.0.0: Methods deprecated for 5 years or longer will be removed
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index f844f98..0850418 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -155,6 +155,11 @@
.. versionchanged:: 6.0
exceptions were renamed and are ending with "Error".
+
+.. versionchanged:: 7.0
+ All Pywikibot Error exceptions must be imported from
+ ``pywikibot.exceptions``. Deprecated exceptions identifiers were
+ removed.
"""
#
# (C) Pywikibot team, 2008-2021
diff --git a/scripts/CHANGELOG.md b/scripts/CHANGELOG.md
index f85a12a..0db9f4c 100644
--- a/scripts/CHANGELOG.md
+++ b/scripts/CHANGELOG.md
@@ -9,9 +9,36 @@
* Deprecated function put_text() was removed in favour of BaseBot.userPut() method
* Deprecated function add_text() were remove in favour of textlib.add_text()
+### blockpageschecker
+* Use different edit comments when adding, changeing or removing templates (T291345)
+* Derive CheckerBot from ConfigParserBot (T57106)
+* Derive CheckerBot from CurrentPageBot (T196851, T171713)
+
+### category
+* Deprecated code parts were removed
+
+### djvutext
+* pass site arg only once (T292367)
+
### newitem
* Do not pass OtherPageSaveRelatedError silently
+### pagefromfile
+* Preload pages instead of reading them one by one before putting changes
+* Don't ask for confirmation by default (T291757)
+
+### reflinks
+* L10N updates
+
+### replace
+* Deprecated "acceptall" and "addedCat" parameters were replaced by "always" and "addcat"
+
+### revertbot
+* Deprecated "max" parameter was replaced by "total"
+
+### solve_disambiguation
+* Remove deprecated properties in favour of DisambiguationRobot.opt options
+
### touch
*Do not pass OtherPageSaveRelatedError silently
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/729142
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I88d004ece927d75e9f6f7151b5b8da745938ca71
Gerrit-Change-Number: 729142
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/710116 )
Change subject: [IMPR] i18n.py type hints
......................................................................
[IMPR] i18n.py type hints
Bug: T286403
Change-Id: Ida30c87350c79d6657461f7514c182a736aa90bf
---
M pywikibot/i18n.py
M pywikibot/plural.py
2 files changed, 56 insertions(+), 35 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index ac015f2..25d751d 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -23,21 +23,32 @@
import os
import pkgutil
import re
-from collections import defaultdict
-from collections.abc import Mapping
+
+from collections import abc, defaultdict
from contextlib import suppress
from textwrap import fill
from typing import Optional, Union
import pywikibot
+
from pywikibot import __url__, config
-from pywikibot.backports import List, cache
+from pywikibot.backports import (
+ cache,
+ Dict,
+ Iterable,
+ Iterator,
+ List,
+ Mapping,
+ Match,
+ Sequence,
+)
from pywikibot.plural import plural_rule
from pywikibot.tools import (
ModuleDeprecationWrapper,
deprecated_args,
)
+STR_OR_SITE_TYPE = Union[str, 'pywikibot.site.BaseSite']
PLURAL_PATTERN = r'{{PLURAL:(?:%\()?([^\)]*?)(?:\)d)?\|(.*?)}}'
@@ -349,10 +360,11 @@
'yi': ['he', 'de'],
'zh-classical': ['zh', 'zh-hans', 'zh-tw', 'zh-cn', 'zh-classical', 'lzh'],
'zh-min-nan': [
- 'cdo', 'zh', 'zh-hans', 'zh-tw', 'zh-cn', 'zh-classical', 'lzh']}
+ 'cdo', 'zh', 'zh-hans', 'zh-tw', 'zh-cn', 'zh-classical', 'lzh']
+} # type: Dict[str, List[str]]
-def set_messages_package(package_name: str):
+def set_messages_package(package_name: str) -> None:
"""Set the package name where i18n messages are located."""
global _messages_package_name
global _messages_available
@@ -413,8 +425,9 @@
message_bundle = twtitle.split('-')[0]
filename = '{}/{}.json'.format(message_bundle, lang)
try:
- trans_text = pkgutil.get_data(
- _messages_package_name, filename).decode('utf-8')
+ data = pkgutil.get_data(_messages_package_name, filename)
+ assert data is not None
+ trans_text = data.decode('utf-8')
except OSError: # file open can cause several exceptions
return None
@@ -422,18 +435,20 @@
return transdict.get(twtitle)
-def _extract_plural(lang: str, message: str, parameters: Mapping) -> str:
+def _extract_plural(lang: str, message: str, parameters: Mapping[str, int]
+ ) -> str:
"""Check for the plural variants in message and replace them.
:param message: the message to be replaced
:param parameters: plural parameters passed from other methods
- :type parameters: Mapping of str to int
:return: The message with the plural instances replaced
"""
- def static_plural_value(n):
- return rule['plural']
+ def static_plural_value(n: int) -> int:
+ plural_rule = rule['plural']
+ assert not callable(plural_rule)
+ return plural_rule
- def replace_plural(match):
+ def replace_plural(match: Match[str]) -> str:
selector = match.group(1)
variants = match.group(2)
num = parameters[selector]
@@ -459,6 +474,8 @@
if num in specific_entries:
return specific_entries[num]
+ assert callable(plural_value)
+
index = plural_value(num)
needed = rule['nplurals']
if needed == 1:
@@ -474,15 +491,17 @@
'parameters is not Mapping but {}'.format(type(parameters))
rule = plural_rule(lang)
- plural_value = rule['plural']
- if not callable(plural_value):
+
+ if callable(rule['plural']):
+ plural_value = rule['plural']
+ else:
assert rule['nplurals'] == 1
plural_value = static_plural_value
return re.sub(PLURAL_PATTERN, replace_plural, message)
-class _PluralMappingAlias(Mapping):
+class _PluralMappingAlias(abc.Mapping):
"""
Aliasing class to allow non mappings in _extract_plural.
@@ -490,15 +509,16 @@
That function only uses __getitem__ so this is only implemented here.
"""
- def __init__(self, source):
+ def __init__(self, source: Union[int, str, Sequence[int],
+ Mapping[str, int]]) -> None:
+ self.source = source
if isinstance(source, str):
self.source = int(source)
- else:
- self.source = source
+
self.index = -1
super().__init__()
- def __getitem__(self, key):
+ def __getitem__(self, key: str) -> int:
self.index += 1
if isinstance(self.source, dict):
return int(self.source[key])
@@ -508,22 +528,23 @@
return int(self.source[self.index])
raise ValueError('Length of parameter does not match PLURAL '
'occurrences.')
+ assert isinstance(self.source, int)
return self.source
- def __iter__(self):
+ def __iter__(self) -> Iterator[int]:
raise NotImplementedError # pragma: no cover
- def __len__(self):
+ def __len__(self) -> int:
raise NotImplementedError # pragma: no cover
DEFAULT_FALLBACK = ('_default', )
-def translate(code,
- xdict: Union[dict, str],
- parameters: Optional[Mapping] = None,
- fallback=False) -> str:
+def translate(code: STR_OR_SITE_TYPE,
+ xdict: Union[str, Mapping[str, str]],
+ parameters: Optional[Mapping[str, int]] = None,
+ fallback: Union[bool, Iterable[str]] = False) -> Optional[str]:
"""Return the most appropriate localization from a localization dict.
Given a site code and a dictionary, returns the dictionary's value for
@@ -542,7 +563,6 @@
extended dictionary the Site object should be used in favour of the
code string. Otherwise localizations from a wrong family might be
used.
- :type code: str or Site object
:param xdict: dictionary with language codes as keys or extended
dictionary with family names as keys containing code dictionaries
or a single string. May contain PLURAL tags as described in
@@ -550,7 +570,6 @@
:param parameters: For passing (plural) parameters
:param fallback: Try an alternate language code. If it's iterable it'll
also try those entries and choose the first match.
- :type fallback: boolean or iterable
:return: the localized string
:raise IndexError: If the language supports and requires more plurals
than defined for the given PLURAL pattern.
@@ -561,6 +580,7 @@
if hasattr(code, 'code'):
family = code.family.name
code = code.code
+ assert isinstance(code, str)
try:
lookup = xdict[code]
@@ -581,6 +601,7 @@
if fallback is True:
codes += _altlang(code) + ['_default', 'en']
elif fallback is not False:
+ assert not isinstance(fallback, bool)
codes.extend(fallback)
for code in codes:
if code in lookup:
@@ -593,7 +614,7 @@
trans = None
if trans is None:
- if 'wikipedia' in xdict:
+ if isinstance(xdict, dict) and 'wikipedia' in xdict:
# fallback to wikipedia family
return translate(code, xdict['wikipedia'],
parameters=parameters, fallback=fallback)
@@ -617,9 +638,11 @@
@deprecated_args(code='source')
-def twtranslate(source,
+def twtranslate(source: STR_OR_SITE_TYPE,
twtitle: str,
- parameters: Optional[Mapping] = None, *,
+ parameters: Union[Sequence[str], Mapping[str, int],
+ None] = None,
+ *,
fallback: bool = True,
fallback_prompt: Optional[str] = None,
only_plural: bool = False) -> Optional[str]:
@@ -676,7 +699,6 @@
:param source: When it's a site it's using the lang attribute and otherwise
it is using the value directly.
- :type source: BaseSite or str
:param twtitle: The TranslateWiki string title, in <package>-<key> format
:param parameters: For passing parameters. It should be a mapping but for
backwards compatibility can also be a list, tuple or a single value.
@@ -742,7 +764,7 @@
@deprecated_args(code='source')
-def twhas_key(source, twtitle: str) -> bool:
+def twhas_key(source: STR_OR_SITE_TYPE, twtitle: str) -> bool:
"""
Check if a message has a translation in the specified language code.
@@ -753,7 +775,6 @@
:param source: When it's a site it's using the lang attribute and otherwise
it is using the value directly.
- :type source: BaseSite or str
:param twtitle: The TranslateWiki string title, in <package>-<key> format
"""
# If a site is given instead of a code, use its language
@@ -787,7 +808,7 @@
def input(twtitle: str,
- parameters: Optional[Mapping] = None,
+ parameters: Optional[Mapping[str, int]] = None,
password: bool = False,
fallback_prompt: Optional[str] = None) -> str:
"""
diff --git a/pywikibot/plural.py b/pywikibot/plural.py
index fc786f0..bb4c9d0 100644
--- a/pywikibot/plural.py
+++ b/pywikibot/plural.py
@@ -9,7 +9,7 @@
from pywikibot.backports import Dict
-PluralRule = Dict[str, Union[int, Callable]]
+PluralRule = Dict[str, Union[int, Callable[[int], Union[bool, int]]]]
plural_rules = {
'_default': {'nplurals': 2, 'plural': lambda n: (n != 1)},
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/710116
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ida30c87350c79d6657461f7514c182a736aa90bf
Gerrit-Change-Number: 710116
Gerrit-PatchSet: 4
Gerrit-Owner: Damian <atagar1(a)gmail.com>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: Isaacandy <isaac(a)iznd.xyz>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged