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
This commit is contained in:
Arturo Escaip 2020-05-26 07:55:21 -07:00 committed by GitHub
parent db098bc1f0
commit 8ad052464a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -1751,7 +1751,7 @@ class LoggerAdapter(object):
information in logging output. 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 Initialize the adapter with a logger and a dict-like object which
provides contextual information. This constructor signature allows provides contextual information. This constructor signature allows

View File

@ -0,0 +1,2 @@
The second argument (extra) of ``LoggerAdapter.__init__`` now defaults to
None.