niccokunzmann/python-recurring-ical-events

Add type hints to better understand source

Closed this issue · 14 comments

I currently try to find out if the between() function can take a date and/or datetime object. I think it can parse both (as that's what I remember I've tested), but I am not sure. Also I do not understand the source with that tuple and int instance checking, thats confusing to me.

Could you please clarify what the accepted inputs of between() are and maybe add this as a typehint?


We're using [Polar.sh](https://polar.sh/niccokunzmann) so you can upvote and help fund this issue. We receive the funding once the issue is completed & confirmed by you. Thank you in advance for helping prioritize & fund our work. Fund with Polar

Ah, now I see. I would not do that, but as long as date and datetime works, thats fine for me.

I just want to note, that if you input an end date as date it will not be included. What I expect the code to do is to combine that with:

if type(before) is date:
    before = datetime.combine(before, datetime.max.time())
if type(after) is date:
    after = datetime.combine(after, datetime.min.time())

yes, the end date is excluded. That should be documented this way if I remember correctly.

It seems that combine is not present.

Python 3.9.5 (default, Nov 23 2021, 15:27:38)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help("datetime.combine")
No Python documentation found for 'datetime.combine'.

Thanks! I could have thought about that :,)
How would you formulate this issue so that it has closing criteria? Is it "Added type hints to at(), between() and of()"?
Or would be copying over examples from the README into the docstring?

I personally would:

  • Add typehints to all public functions
  • Think if a function should take 5 different types of variables, or if date|datetime isn't already enough
  • Documenting the private function would also help you to build clearer and better understandable source code.

And I have to correct myself:

        if type(start) is date:
            start = datetime.combine(start, datetime.min.time())
        if type(end) is date:
            end = datetime.combine(end + timedelta(days=1), datetime.min.time())

Is better

Hm. I just saw this example concerning py.typed: https://github-redirect.dependabot.com/certifi/python-certifi/issues/196 That reminded me of this issue.

If someone likes to add type hints, this is welcome. I will support that but not do it myself at the moment.

Why? It is so much easier to understand your own code. At least for newer code this should be done. You can also then do typechecks using pylance in vscode.

This is fixed in v3.0.0