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

login
register
mail settings
Submitter Pulkit Goyal
Date Nov. 2, 2016, 10:15 p.m.
Message ID <8cd0e855ebb448a4ec1e.1478124920@pulkit-goyal>
Download mbox | patch
Permalink /patch/17296/
State Superseded
Headers show

Comments

Pulkit Goyal - Nov. 2, 2016, 10:15 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@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.

Patch

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 []