Skip to content

ValueError is raised instead of returning None for 'parse(". day")' #15

@Delgan

Description

@Delgan

Hello.

I just noticed a small bug. This is not very important, but it's a little inconsistent with the rest of the library which returns None when unable to parse the string.

>>> from pytimeparse import parse
>>> parse(". day")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/env/lib/python3.6/site-packages/pytimeparse/timeparse.py", line 176, in timeparse
    list(mdict.items()) if k != 'secs' and v is not None])) +
  File "/home/env/lib/python3.6/site-packages/pytimeparse/timeparse.py", line 176, in <listcomp>
    list(mdict.items()) if k != 'secs' and v is not None])) +
ValueError: could not convert string to float: '.'

Python 3.6.3 and pytimeparse 1.1.7.

I guess this is because of the regex [\d.]+ which do not filter out such wrongly formatted float values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions