ioces / toshling

a Python client library for the Toshl API
MIT License
4 stars 1 forks source link

Missing validator for date strings #2

Closed jfthuong closed 3 years ago

jfthuong commented 3 years ago

When I run the following:

from toshling import Client

TOKEN = Path("API_KEY").read_text()
client = Client(TOKEN)

entries = client.entries.list(from_="2021-06-26", to="2021-06-27")
for e in entries:
    print(e)

I have the following warning:

C:\Python37-32\lib\site-packages\statham\schema\validation\format.py:39: RuntimeWarning: No validator found for format string date. To register new formats, please register a checker with statham.schema.validation.format.format_checker as follows:

@format_checker(date)
def is_date(value) -> bool:
    ...
jfthuong commented 3 years ago

Need to add somewhere (e.g. in _client.py), the following

import re
...
from statham.schema.validation import format_checker

@format_checker.register("date")
def is_date(value: str) -> bool:
    return bool(re.match(r"\d{4}-\d{2}-\d{2}", value))
m-schubert commented 3 years ago

Can you please open a pull request for the changes? I'd also recommend doing it in a branch other than master, if at all possible. It means that if the PR is squashed and merged, your master won't have diverged from this one.

jfthuong commented 3 years ago

I will try to work on branches in the future... and I will try to do a PR when I have time (I'm not that familiar with PR :) )

m-schubert commented 3 years ago

Excellent. It looks like you're doing good work. The PR process just makes it a bit easier to separate out all of the changes you're making and review them one-by-one.

Give a PR a shot, and I can help guide you through the process. If it gets too tricky to separate out your changes now, create one generic PR for all of your current commits and I'll pick/choose the changes you've made, merge and then you can base your future updates off the updated master.

jfthuong commented 3 years ago

Don't worry, I will have a training on Git on Monday so I will ask the trainer to help me do it ;)

m-schubert commented 3 years ago

Fixed by #6