[PATCH 6 of 7] py3: use try/except to check for basestring

Pulkit Goyal 7895pulkit at gmail.com
Wed Nov 2 18:15:20 EDT 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1478121825 -19800
#      Thu Nov 03 02:53:45 2016 +0530
# Node ID 8cd0e855ebb448a4ec1e835b346a920a1cb835cb
# Parent  495481800cc65bddf8a944ce0a091fef5972c6b9
py3: use try/except to check for basestring

The term basestring don't exist in Python 3.5 and throws a NameError.
It used to refer to unicodes in Python 2. Used try/expect to handle this.

diff -r 495481800cc6 -r 8cd0e855ebb4 mercurial/ui.py
--- a/mercurial/ui.py	Thu Nov 03 02:27:46 2016 +0530
+++ b/mercurial/ui.py	Thu Nov 03 02:53:45 2016 +0530
@@ -520,7 +520,12 @@
         result = self.config(section, name, untrusted=untrusted)
         if result is None:
             result = default or []
-        if isinstance(result, basestring):
+        checkunicode = False
+        try:
+            checkunicode = isinstance(result, basestring)
+        except NameError:
+            checkunicode = isinstance(result, str)
+        if checkunicode:
             result = _configlist(result.lstrip(' ,\n'))
             if result is None:
                 result = default or []


More information about the Mercurial-devel mailing list