jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1101200?usp=email )
Change subject: cleanup: remove positional arguments for logging functions ......................................................................
cleanup: remove positional arguments for logging functions
Also enable args as formatting parameters
Bug: T378898 Change-Id: I814a92e8b86ff13d98327b68443c7d779e166f4b --- M ROADMAP.rst M pywikibot/logging.py 2 files changed, 55 insertions(+), 55 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst index fb8c82a..b5b5478 100644 --- a/ROADMAP.rst +++ b/ROADMAP.rst @@ -3,6 +3,7 @@
**Improvements**
+* *args* parameter for :mod:`logging` functions can be used as formatting arguments * :attr:`.login.OauthLoginManager.access_token` was added. * Representation string for :class:`login.LoginManager` was added. * i18n updates. @@ -13,6 +14,8 @@
**Code cleanups**
+* Positional arguments *decoder*, *layer* and *newline* for :mod:`logging` functions are invalid; + keyword arguments must be used instead. * The positional arguments of :meth:`page.BasePage.linkedPages` were removed. * ``FilePage.usingPages()`` was renamed to :meth:`using_pages()<pywikibot.FilePage.using_pages>`. * ``APISite.article_path`` was removed. :attr:`APISite.articlepath @@ -116,8 +119,6 @@ * 9.4.0: :mod:`flow` support is deprecated and will be removed (:phab:`T371180`) * 7.3.0: ``linktrail`` method of :class:`family.Family` is deprecated; use :meth:`APISite.linktrail() <pywikibot.site._apisite.APISite.linktrail>` instead -* 7.2.0: Positional arguments *decoder*, *layer* and *newline* for :mod:`logging` functions were dropped; keyword - arguments must be used instead. * 7.2.0: ``tb`` parameter of :func:`exception()<pywikibot.logging.exception>` function was renamed to ``exc_info`` * 7.1.0: Unused ``get_redirect`` parameter of :meth:`Page.getOldVersion()<page.BasePage.getOldVersion>` will be removed * 7.0.0: baserevid parameter of editSource(), editQualifier(), removeClaims(), removeSources(), remove_qualifiers() diff --git a/pywikibot/logging.py b/pywikibot/logging.py index ef028ce..7dc1f21 100644 --- a/pywikibot/logging.py +++ b/pywikibot/logging.py @@ -48,7 +48,6 @@ from typing import Any
from pywikibot.backports import Callable -from pywikibot.tools import deprecated_args, issue_deprecation_warning
STDOUT = 16 #: @@ -82,8 +81,6 @@ _init_routines[:] = [] # the global variable is used with slice operator
-# Note: The frame must be updated if this decorator is removed -@deprecated_args(text='msg') # since 7.2 def logoutput(msg: Any, *args: Any, level: int = INFO, @@ -94,20 +91,30 @@ functions. It can be used to implement your own high-level output function with a different logging level.
- `msg` can contain special sequences to create colored output. These + *msg* can contain special sequences to create colored output. These consist of the color name in angle bracket, e. g. <<lightpurple>>. <<default>> resets the color.
- Other keyword arguments are passed unchanged to the logger; so far, - the only argument that is useful is ``exc_info=True``, which causes - the log message to include an exception traceback. + *args* are the arguments which are merged into *msg* using the + string formatting operator. It is passed unchanged to the logger. + + .. attention:: Only old ``%``-formatting is supported for *args* by + the :pylib:`logging` module. + + Keyword arguments other than those listed below are also passed + unchanged to the logger; so far, the only argument that is useful is + ``exc_info=True``, which causes the log message to include an + exception traceback.
.. versionchanged:: 7.2 Positional arguments for *decoder* and *newline* are deprecated; keyword arguments should be used. + .. versionchanged:: 10.0 + *args* parameter can now given as formatting arguments directly + to the logger.
:param msg: The message to be printed. - :param args: Not used yet; prevents positional arguments except `msg`. + :param args: Passed as string formatter options to the logger. :param level: The logging level; supported by :func:`logoutput` only. :keyword bool newline: If newline is True (default), a line feed will be added after printing the msg. @@ -122,35 +129,12 @@ if _init_routines: _init()
- keys: tuple[str, ...] - # cleanup positional args - if level == ERROR: - keys = ('decoder', 'newline', 'exc_info') - elif level == DEBUG: - keys = ('layer', 'decoder', 'newline') - else: - keys = ('decoder', 'newline') - - for i, arg in enumerate(args): - key = keys[i] - issue_deprecation_warning( - f'Positional argument {i + 1} ({arg})', - f'keyword argument "{key}={arg}"', - since='7.2.0') - if key in kwargs: - warning(f'{key!r} is given as keyword argument {arg!r} already; ' - f'ignoring {kwargs[key]!r}') - else: - kwargs[key] = arg - # frame 0 is logoutput() in this module, - # frame 1 is the deprecation wrapper of this function - # frame 2 is the convenience function (output(), etc.) - # frame 3 is the deprecation wrapper the convenience function - # frame 4 is whatever called the convenience function - newline = kwargs.pop('newline', True) - frame = sys._getframe(4) + # frame 1 is the convenience function (info(), etc.) + # frame 2 is whatever called the convenience function + frame = sys._getframe(2) module = os.path.basename(frame.f_code.co_filename) + newline = kwargs.pop('newline', True) context = {'caller_name': frame.f_code.co_name, 'caller_file': module, 'caller_line': frame.f_lineno, @@ -166,22 +150,30 @@
layer = kwargs.pop('layer', '') logger = logging.getLogger(('pywiki.' + layer).strip('.')) - logger.log(level, msg, extra=context, **kwargs) + logger.log(level, msg, *args, extra=context, **kwargs)
-# Note: The logoutput frame must be updated if this decorator is removed -@deprecated_args(text='msg') # since 7.2 def info(msg: Any = '', *args: Any, **kwargs: Any) -> None: """Output a message to the user with level :const:`INFO`.
``msg`` will be sent to stderr via :mod:`pywikibot.userinterfaces`. It may be omitted and a newline is printed in that case. - The arguments are interpreted as for :func:`logoutput`. + The arguments are interpreted as for :func:`logoutput`. *args* can + be uses as formatting arguments for all logging functions of this + module. But this works for old ``%``-formatting only: + + >>> info('Hello %s', 'World') # doctest: +SKIP + Hello World + >>> info('Pywikibot %(version)d', {'version': 10}) # doctest: +SKIP + Pywikibot 10
.. versionadded:: 7.2 was renamed from :func:`output`. Positional arguments for *decoder* and *newline* are deprecated; keyword arguments should be used. Keyword parameter *layer* was added. + .. versionchanged:: 10.0 + *args* parameter can now given as formatting arguments directly + to the logger.
.. seealso:: :python:`Logger.info()<library/logging.html#logging.Logger.info>` @@ -202,8 +194,6 @@ """
-# Note: The logoutput frame must be updated if this decorator is removed -@deprecated_args(text='msg') # since 7.2 def stdout(msg: Any = '', *args: Any, **kwargs: Any) -> None: """Output script results to the user with level :const:`STDOUT`.
@@ -218,6 +208,9 @@ `text` was renamed to `msg`; `msg` parameter may be omitted; only keyword arguments are allowed except for `msg`. Keyword parameter *layer* was added. + .. versionchanged:: 10.0 + *args* parameter can now given as formatting arguments directly + to the logger. .. seealso:: - :python:`Logger.log()<library/logging.html#logging.Logger.log>` - :wiki:`Pipeline (Unix)` @@ -225,8 +218,6 @@ logoutput(msg, *args, level=STDOUT, **kwargs)
-# Note: The logoutput frame must be updated if this decorator is removed -@deprecated_args(text='msg') # since 7.2 def warning(msg: Any, *args: Any, **kwargs: Any) -> None: """Output a warning message to the user with level :const:`WARNING`.
@@ -236,14 +227,15 @@ .. versionchanged:: 7.2 `text` was renamed to `msg`; only keyword arguments are allowed except for `msg`. Keyword parameter *layer* was added. + .. versionchanged:: 10.0 + *args* parameter can now given as formatting arguments directly + to the logger. .. seealso:: :python:`Logger.warning()<library/logging.html#logging.Logger.warning>` """ logoutput(msg, *args, level=WARNING, **kwargs)
-# Note: The logoutput frame must be updated if this decorator is removed -@deprecated_args(text='msg') # since 7.2 def error(msg: Any, *args: Any, **kwargs: Any) -> None: """Output an error message to the user with level :const:`ERROR`.
@@ -253,14 +245,15 @@ .. versionchanged:: 7.2 `text` was renamed to `msg`; only keyword arguments are allowed except for `msg`. Keyword parameter *layer* was added. + .. versionchanged:: 10.0 + *args* parameter can now given as formatting arguments directly + to the logger. .. seealso:: :python:`Logger.error()<library/logging.html#logging.Logger.error>` """ logoutput(msg, *args, level=ERROR, **kwargs)
-# Note: The logoutput frame must be updated if this decorator is removed -@deprecated_args(text='msg') # since 7.2 def log(msg: Any, *args: Any, **kwargs: Any) -> None: """Output a record to the log file with level :const:`VERBOSE`.
@@ -269,14 +262,15 @@ .. versionchanged:: 7.2 `text` was renamed to `msg`; only keyword arguments are allowed except for `msg`. Keyword parameter *layer* was added. + .. versionchanged:: 10.0 + *args* parameter can now given as formatting arguments directly + to the logger. .. seealso:: :python:`Logger.log()<library/logging.html#logging.Logger.log>` """ logoutput(msg, *args, level=VERBOSE, **kwargs)
-# Note: The logoutput frame must be updated if this decorator is removed -@deprecated_args(text='msg') # since 7.2 def critical(msg: Any, *args: Any, **kwargs: Any) -> None: """Output a critical record to the user with level :const:`CRITICAL`.
@@ -286,6 +280,9 @@ .. versionchanged:: 7.2 `text` was renamed to `msg`; only keyword arguments are allowed except for `msg`. Keyword parameter *layer* was added. + .. versionchanged:: 10.0 + *args* parameter can now given as formatting arguments directly + to the logger. .. seealso:: :python:`Logger.critical() <library/logging.html#logging.Logger.critical>` @@ -293,8 +290,6 @@ logoutput(msg, *args, level=CRITICAL, **kwargs)
-# Note: The logoutput frame must be updated if this decorator is removed -@deprecated_args(text='msg') # since 7.2 def debug(msg: Any, *args: Any, **kwargs: Any) -> None: """Output a debug record to the log file with level :const:`DEBUG`.
@@ -303,14 +298,15 @@ .. versionchanged:: 7.2 `layer` parameter is optional; `text` was renamed to `msg`; only keyword arguments are allowed except for `msg`. + .. versionchanged:: 10.0 + *args* parameter can now given as formatting arguments directly + to the logger. .. seealso:: :python:`Logger.debug()<library/logging.html#logging.Logger.debug>` """ logoutput(msg, *args, level=DEBUG, **kwargs)
-# Note: The logoutput frame must be updated if this decorator is removed -@deprecated_args(tb='exc_info') # since 7.2 def exception(msg: Any = None, *args: Any, exc_info: bool = True, **kwargs: Any) -> None: """Output an error traceback to the user with level :const:`ERROR`. @@ -341,6 +337,9 @@ parameter *layer* was added. .. versionchanged:: 7.3 `exc_info` is True by default + .. versionchanged:: 10.0 + *args* parameter can now given as formatting arguments directly + to the logger. .. seealso:: :python:`Logger.exception() <library/logging.html#logging.Logger.exception>`
pywikibot-commits@lists.wikimedia.org