[Python-checkins] cpython (2.7): Issue #21172: isinstance check relaxed from dict to collections.Mapping.

vinay.sajip python-checkins at python.org
Thu Apr 10 08:14:15 CEST 2014


http://hg.python.org/cpython/rev/d08e3586dde3
changeset:   90214:d08e3586dde3
branch:      2.7
parent:      90212:340a9d2f6bde
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Thu Apr 10 07:07:59 2014 +0100
summary:
  Issue #21172: isinstance check relaxed from dict to collections.Mapping.

files:
  Lib/logging/__init__.py |  10 ++++++++--
  Misc/NEWS               |   2 ++
  2 files changed, 10 insertions(+), 2 deletions(-)


diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -23,7 +23,7 @@
 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 @@
         # '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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -43,6 +43,8 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list