Page MenuHomePhabricator

APISite.upload(): "report_success" and "ignore_warnings" parameter should be rethinked
Open, MediumPublic

Description

With rPWBCb167da7 a dependency of "report_success" and "ignore_warnings" parameters was introduced which is really unclear:

@type ignore_warnings: bool or callable or iterable of str
@type report_success: Optional[bool]
...
if report_success is None:
    report_success = isinstance(ignore_warnings, bool)
if report_success is True:
    if not isinstance(ignore_warnings, bool):
        raise ValueError('report_success may only be set to True when '
                         'ignore_warnings is a boolean')
    issue_deprecation_warning('"ignore_warnings" as a boolean and '
                              '"report_success" is True or None',
                              '"report_success=False" or define '
                              '"ignore_warnings" as callable/iterable',
                              3, warning_class=FutureWarning,
                              since='20150823')

if report_success is True it raises a ValueError if ignore_warnings is not a boolean but the same case if ignore_warnings is a boolean a DeprecationWarning/FutureWarning is printed that ignore_warnings must be a callable or iterable in that case. Strange

Event Timeline

Change 655878 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] Don't print a FutureWarning until T271899 is solved

https://gerrit.wikimedia.org/r/655878

Change 655878 merged by jenkins-bot:
[pywikibot/core@master] Don't print a FutureWarning until T271899 is solved

https://gerrit.wikimedia.org/r/655878

Change 758046 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [cleanup] Remove deprecatin warning for ignore_warnings/report_success

https://gerrit.wikimedia.org/r/758046

Change 758046 merged by jenkins-bot:

[pywikibot/core@master] [cleanup] Remove deprecation warning for ignore_warnings/report_success

https://gerrit.wikimedia.org/r/758046

See also masked DeprecationWarning introduced with rPWBCd0d1c83

Change 762108 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [cleanup] Remove unclear DeprecatinWarning for ignore_warnings parameter

https://gerrit.wikimedia.org/r/762108

Change 762108 merged by jenkins-bot:

[pywikibot/core@master] [cleanup] Remove unclear DeprecatinWarning for ignore_warnings parameter

https://gerrit.wikimedia.org/r/762108

I just wanted to comment here, because this behavior is really unclear to me. Does it mean that if I am using the ignore_warnings iterable functionality, I lose access to the message of warnings? I would like to make a bot workflow that raises an error on certain warnings, but then makes a certain action based on the content of the warning received by the API. For example, if the warning is a duplicate one, I might do something after the upload attempt, like move the existing file to the preferred title—but I can't see what it was without logging the warning. Is there a different way to get access to it?