Page MenuHomePhabricator

logging fails in python3 when deprecated_args decorators (or similar) is used
Closed, ResolvedPublic

Description

import pywikibot
import pywikibot.logging

from pywikibot.bot import init_handlers
from pywikibot.tools import deprecated_args

_logger = 'test'

@deprecated_args(x='y')
def bar(y):
    pass
user@pc:~/python/core {master}$ python3 test_warn.py 
WARNING: test_warn.py:19: DeprecationWarning: x argument of __main__.bar is deprecated; use y instead.
  bar(x=3)

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.4/logging/handlers.py", line 71, in emit
    if self.shouldRollover(record):
  File "/usr/lib/python3.4/logging/handlers.py", line 187, in shouldRollover
    msg = "%s\n" % self.format(record)
  File "/home/user/python/core/pywikibot/tools/_logging.py", line 88, in format
    'Record argument should start with path'
AssertionError: Record argument should start with path
Call stack:
  File "test_warn.py", line 19, in <module>
    bar(x=3)
  File "/home/user/python/core/pywikibot/tools/__init__.py", line 1437, in wrapper
    DeprecationWarning, depth)
Message: '%s'
Arguments: ('test_warn.py:19: DeprecationWarning: x argument of __main__.bar is deprecated; use y instead.\n  bar(x=3)\n',)
user@pc:~/python/core {master}$ python2 test_warn.py 
WARNING: test_warn.py:19: DeprecationWarning: x argument of __main__.bar is deprecated; use y instead.
  bar(x=3)

Event Timeline

Change 342122 had a related patch set uploaded (by Mpaa):
[pywikibot/core] Fix logging in python3 when deprecated_args decorator is used

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

With the patch the outcome is now in python 2.7, 3.4 and 3.6:

2017-03-09 23:25:32 /home/user/python/core/pywikibot/tools/__init__.py, 1437 in           __init__: WARNING  test_warn.py:22: DeprecationWarning: x argument of test_warn_sub.bar is deprecated; use y instead.
  bar(x=3)
2017-03-09 23:25:32            http.py,  131 in             _flush: VERBOSE  Closing network session.
2017-03-09 23:25:32            http.py,  133 in             _flush: VERBOSE  Network session closed.


2017-03-09 23:25:35 /home/user/python/core/pywikibot/tools/__init__.py, 1437 in           __init__: WARNING  test_warn.py:22: DeprecationWarning: x argument of test_warn_sub.bar is deprecated; use y instead.
  bar(x=3)
2017-03-09 23:25:35            http.py,  131 in             _flush: VERBOSE  Closing network session.
2017-03-09 23:25:35            http.py,  133 in             _flush: VERBOSE  Network session closed.


2017-03-09 23:25:39 /home/user/anaconda3/lib/python3.6/warnings.py,   99 in           warnings: WARNING  test_warn.py:22: DeprecationWarning: x argument of test_warn_sub.bar is deprecated; use y instead.
  bar(x=3)
2017-03-09 23:25:39            http.py,  131 in             _flush: VERBOSE  Closing network session.
2017-03-09 23:25:39            http.py,  133 in             _flush: VERBOSE  Network session closed.
Mpaa updated the task description. (Show Details)

Change 342122 merged by jenkins-bot:
[pywikibot/core] Fix logging in python3 when deprecated_args decorator is used

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

Xqt claimed this task.