summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2014-04-10 06:07:59 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2014-04-10 06:07:59 (GMT)
commit5aad46e5c3572d7d07c4e108a60cc793d6d3991a (patch)
tree815488b602fac583d2f84adb492b64fe67eda174
parent00109c9bd3b5c14e8281addc79a79fda3c310806 (diff)
downloadcpython-5aad46e5c3572d7d07c4e108a60cc793d6d3991a.zip
cpython-5aad46e5c3572d7d07c4e108a60cc793d6d3991a.tar.gz
cpython-5aad46e5c3572d7d07c4e108a60cc793d6d3991a.tar.bz2
Issue #21172: isinstance check relaxed from dict to collections.Mapping.
-rw-r--r--Lib/logging/__init__.py10
-rw-r--r--Misc/NEWS2
2 files changed, 10 insertions, 2 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 74f3a5f..b2a7711 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -23,7 +23,7 @@ Copyright (C) 2001-2014 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
-import sys, os, time, cStringIO, traceback, warnings, weakref
+import sys, os, time, cStringIO, traceback, warnings, weakref, collections
__all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
'FATAL', 'FileHandler', 'Filter', 'Formatter', 'Handler', 'INFO',
@@ -261,7 +261,13 @@ class LogRecord(object):
# 'Value is %d' instead of 'Value is 0'.
# For the use case of passing a dictionary, this should not be a
# problem.
- if args and len(args) == 1 and isinstance(args[0], dict) and args[0]:
+ # Issue #21172: a request was made to relax the isinstance check
+ # to hasattr(args[0], '__getitem__'). However, the docs on string
+ # formatting still seem to suggest a mapping object is required.
+ # Thus, while not removing the isinstance check, it does now look
+ # for collections.Mapping rather than, as before, dict.
+ if (args and len(args) == 1 and isinstance(args[0], collections.Mapping)
+ and args[0]):
args = args[0]
self.args = args
self.levelname = getLevelName(level)
diff --git a/Misc/NEWS b/Misc/NEWS
index 7756e89..7fef5b5 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -43,6 +43,8 @@ Core and Builtins
Library
-------
+- Issue #21172: isinstance check relaxed from dict to collections.Mapping.
+
- Issue #21191: In os.fdopen, alwyas close the file descriptor when an exception
happens.