[PATCH 6 of 7] py3: use try/except to check for basestring
Yuya Nishihara
yuya at tcha.org
Thu Nov 3 23:51:08 EDT 2016
On Thu, 03 Nov 2016 03:53:11 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1478121825 -19800
> # Thu Nov 03 02:53:45 2016 +0530
> # Node ID aef03902a5c1a13e9775059a5efdeb2466399ada
> # Parent 9e259e7b59b6358eb842eabbc99f4c18a4cc5009
> 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 9e259e7b59b6 -r aef03902a5c1 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'))
Given "result" is a source variable of a list to be returned, it shouldn't
be a unicode. So we can simply use bytes instead of basestring here.
More information about the Mercurial-devel
mailing list