Skip to content

Commit

Permalink
Simplify parser._timelex handling of bytes and bytearray
Browse files Browse the repository at this point in the history
We can handle both bytes and bytearray in the same way in Python 2 and
Python 3.

Co-authored-by: Mario Corchero <mariocj89@gmail.com>
  • Loading branch information
frenzymadness and mariocj89 committed May 20, 2021
1 parent 43b7838 commit 1426acd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/1060.misc.rst
@@ -0,0 +1 @@
Simplify handling of bytes and bytearray in _parser._timelex. Reported and fixed by @frenzymadness (gh issue #1060).
10 changes: 2 additions & 8 deletions dateutil/parser/_parser.py
Expand Up @@ -60,14 +60,8 @@ class _timelex(object):
_split_decimal = re.compile("([.,])")

def __init__(self, instream):
if six.PY2:
# In Python 2, we can't duck type properly because unicode has
# a 'decode' function, and we'd be double-decoding
if isinstance(instream, (bytes, bytearray)):
instream = instream.decode()
else:
if getattr(instream, 'decode', None) is not None:
instream = instream.decode()
if isinstance(instream, (bytes, bytearray)):
instream = instream.decode()

if isinstance(instream, text_type):
instream = StringIO(instream)
Expand Down

0 comments on commit 1426acd

Please sign in to comment.