Skip to content

Commit 8ad0524

Browse files
authored
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
1 parent db098bc commit 8ad0524

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Lib/logging/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ class LoggerAdapter(object):
17511751
information in logging output.
17521752
"""
17531753

1754-
def __init__(self, logger, extra):
1754+
def __init__(self, logger, extra=None):
17551755
"""
17561756
Initialize the adapter with a logger and a dict-like object which
17571757
provides contextual information. This constructor signature allows
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The second argument (extra) of ``LoggerAdapter.__init__`` now defaults to
2+
None.

0 commit comments

Comments
 (0)