From 65c2b1e1d17e7f444b965a5eeefa2af8f0d61216 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Tue, 16 Jul 2019 14:07:04 +0000 Subject: [PATCH] fix_encoding: Do unicode type checks only on Python 2 The unicode type doesn't exist in Python 3, because everything's Unicode. This would resulted in the following error on Python 3: >.write: NameError("name 'unicode' is not defined") Bug: 942522 Change-Id: I3e90d078df64abcec2c79aa69881deea40ff7d01 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1701401 Reviewed-by: Dirk Pranke Commit-Queue: Raul Tambre Auto-Submit: Raul Tambre --- fix_encoding.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fix_encoding.py b/fix_encoding.py index c8f64ff75..e22878c40 100644 --- a/fix_encoding.py +++ b/fix_encoding.py @@ -212,7 +212,7 @@ class WinUnicodeConsoleOutput(WinUnicodeOutputBase): def write(self, text): try: - if not isinstance(text, unicode): + if sys.version_info.major == 2 and not isinstance(text, unicode): # Convert to unicode. text = str(text).decode(self.encoding, 'replace') remaining = len(text) @@ -262,7 +262,7 @@ class WinUnicodeOutput(WinUnicodeOutputBase): def write(self, text): try: - if isinstance(text, unicode): + if sys.version_info.major == 2 and isinstance(text, unicode): # Replace characters that cannot be printed instead of failing. text = text.encode(self.encoding, 'replace') self._stream.write(text)