Skip to content

Commit 6e38d18

Browse files
committed
Make try_decode a no-op in Python 3
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent 84b34ef commit 6e38d18

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

bpython/_py3compat.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ def prepare_for_exec(arg, encoding=None):
5151
return arg.encode(encoding)
5252

5353

54-
def try_decode(s, encoding):
55-
"""Try to decode s which is str names. Return None if not decodable"""
56-
if not py3 and not isinstance(s, unicode):
57-
try:
58-
return s.decode(encoding)
59-
except UnicodeDecodeError:
60-
return None
61-
return s
54+
if py3:
55+
def try_decode(s, encoding):
56+
return s
57+
else:
58+
def try_decode(s, encoding):
59+
"""Try to decode s which is str names. Return None if not decodable"""
60+
if not isinstance(s, unicode):
61+
try:
62+
return s.decode(encoding)
63+
except UnicodeDecodeError:
64+
return None
65+
return s

0 commit comments

Comments
 (0)