Skip to content

dateutil.parse.parse() rejects bytearray as input #417

@uckelman

Description

@uckelman
>>> import dateutil.parser
>>> dateutil.parser.parse(b'17 Jan 2017')
datetime.datetime(2017, 1, 17, 0, 0)
>>> dateutil.parser.parse(bytearray(b'17 Jan 2017'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/site-packages/dateutil/parser.py", line 1168, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/usr/lib/python3.5/site-packages/dateutil/parser.py", line 556, in parse
    res, skipped_tokens = self._parse(timestr, **kwargs)
  File "/usr/lib/python3.5/site-packages/dateutil/parser.py", line 675, in _parse
    l = _timelex.split(timestr)         # Splits the timestr into tokens
  File "/usr/lib/python3.5/site-packages/dateutil/parser.py", line 192, in split
    return list(cls(s))
  File "/usr/lib/python3.5/site-packages/dateutil/parser.py", line 61, in __init__
    '{itype}'.format(itype=instream.__class__.__name__))
TypeError: Parser must be a string or character stream, not bytearray

Any function which can operate on a bytes ought to be able to operate on a bytearray---unless something has specifically been done to prevent that, as in dateutil.parser.parse(). When bytes works, it's unexpected that bytearray would fail. It would be better to accept bytearrays as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions