]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Remove python2 support in logging cookbook example. (GH-32362)
authorMathieu Dupuy <mathieu.dupuy@critizr.com>
Wed, 6 Apr 2022 16:57:54 +0000 (18:57 +0200)
committerGitHub <noreply@github.com>
Wed, 6 Apr 2022 16:57:54 +0000 (17:57 +0100)
Doc/howto/logging-cookbook.rst

index f0d944940fc28f324a631b22dd2bec6aa4f6290d..704279240b357b853e0594c202ffb3d1a60583d0 100644 (file)
@@ -1788,22 +1788,15 @@ Python used.
 If you need more specialised processing, you can use a custom JSON encoder,
 as in the following complete example::
 
-    from __future__ import unicode_literals
-
     import json
     import logging
 
-    # This next bit is to ensure the script runs unchanged on 2.x and 3.x
-    try:
-        unicode
-    except NameError:
-        unicode = str
 
     class Encoder(json.JSONEncoder):
         def default(self, o):
             if isinstance(o, set):
                 return tuple(o)
-            elif isinstance(o, unicode):
+            elif isinstance(o, str):
                 return o.encode('unicode_escape').decode('ascii')
             return super().default(o)