]> granicus.if.org Git - python/commitdiff
Issue #21172: isinstance check relaxed from dict to collections.Mapping.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Thu, 10 Apr 2014 06:07:59 +0000 (07:07 +0100)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Thu, 10 Apr 2014 06:07:59 +0000 (07:07 +0100)
Lib/logging/__init__.py
Misc/NEWS

index 74f3a5f5dd93fc41d3c8a299348865a039f74b8c..b2a7711dc36878538739db9d7b630bb27689a15d 100644 (file)
@@ -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)
index 7756e89c3da3831a9ffd9570abdc326d6c9cbd64..7fef5b5e1e4d14c09eb9b52b850279261abf33c2 100644 (file)
--- 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.