From d0a30b1f84fd53d513475ef950bdf10c734017b8 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 5 Aug 2019 16:09:30 -0400 Subject: [PATCH] py3: add string_or_unicode to polyglot To facilitate universal __future__s, we prefer native_string_type to str. Since we cannot compare things as instance(f, (str, unicode_type)) and it gets a bit ridiculous to compare: from polyglot.builtins import native_string_type, unicode_type isinstance(f, (native_string_type, unicode_type)) allow using isinstance(f, string_or_unicode) instead. This matches the existing string_or_bytes comparator. --- src/polyglot/builtins.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/polyglot/builtins.py b/src/polyglot/builtins.py index bf036ff459..cb78f7f822 100644 --- a/src/polyglot/builtins.py +++ b/src/polyglot/builtins.py @@ -72,6 +72,7 @@ if is_py3: codepoint_to_chr = chr unicode_type = str string_or_bytes = str, bytes + string_or_unicode = str long_type = int raw_input = input getcwd = os.getcwd @@ -126,6 +127,7 @@ else: codepoint_to_chr = unichr unicode_type = unicode string_or_bytes = unicode, bytes + string_or_unicode = str, unicode long_type = long exec_path = execfile raw_input = builtins.raw_input