[Python-checkins] bpo-40756: Default second argument of LoggerAdapter.__init__ to None (GH-20362)

Arturo Escaip webhook-mailer at python.org
Tue May 26 10:55:26 EDT 2020


https://github.com/python/cpython/commit/8ad052464a4e0aef9a11663b80f187087b773592
commit: 8ad052464a4e0aef9a11663b80f187087b773592
branch: master
author: Arturo Escaip <arturo.escaip at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-05-26T07:55:21-07:00
summary:

bpo-40756: Default second argument of LoggerAdapter.__init__ to None (GH-20362)



The 'extra' argument is not always used by custom logger adapters. For
example:

```python
class IndentAdapter(logging.LoggerAdapter):
    def process(self, msg, kwargs):
        indent = kwargs.pop(indent, 1)
        return ' ' * indent + msg, kwargs
```

It is cleaner and friendlier to default the 'extra' argument to None
instead of either forcing the subclasses of LoggerAdapter to pass a None
value directly or to override the constructor.

This change is backward compatible because existing calls to
`LoggerAdapter.__init__` are already passing a value for the second
argument.

Automerge-Triggered-By: @vsajip

files:
A Misc/NEWS.d/next/Library/2020-05-24-11-06-37.bpo-40756.7ZH83z.rst
M Lib/logging/__init__.py

diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 403dc81b13ef4..6d27301a7056e 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1751,7 +1751,7 @@ class LoggerAdapter(object):
     information in logging output.
     """
 
-    def __init__(self, logger, extra):
+    def __init__(self, logger, extra=None):
         """
         Initialize the adapter with a logger and a dict-like object which
         provides contextual information. This constructor signature allows
diff --git a/Misc/NEWS.d/next/Library/2020-05-24-11-06-37.bpo-40756.7ZH83z.rst b/Misc/NEWS.d/next/Library/2020-05-24-11-06-37.bpo-40756.7ZH83z.rst
new file mode 100644
index 0000000000000..a970f5be156f5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-05-24-11-06-37.bpo-40756.7ZH83z.rst
@@ -0,0 +1,2 @@
+The second argument (extra) of ``LoggerAdapter.__init__`` now defaults to
+None.



More information about the Python-checkins mailing list