From 80625ee2a67c9654230bc0617c8911a3d26ea16c Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Fri, 8 Jan 2021 16:26:30 +0100 Subject: Avoid exception chaining on Python 3. This avoids exceptions raised by errors='strict' from displaying as "During handling of the above exception ..." in the backtrace which can be confusing. --- unidecode/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'unidecode') diff --git a/unidecode/__init__.py b/unidecode/__init__.py index 54c543d..776d6e4 100644 --- a/unidecode/__init__.py +++ b/unidecode/__init__.py @@ -65,11 +65,14 @@ def unidecode_expect_ascii(string, errors='ignore', replace_str='?'): try: bytestring = string.encode('ASCII') except UnicodeEncodeError: - return _unidecode(string, errors, replace_str) - if version_info[0] >= 3: - return string + pass else: - return bytestring + if version_info[0] >= 3: + return string + else: + return bytestring + + return _unidecode(string, errors, replace_str) def unidecode_expect_nonascii(string, errors='ignore', replace_str='?'): """Transliterate an Unicode object into an ASCII string -- cgit v1.2.1