Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hints to better understand source #91

Open
NicoHood opened this issue Jun 16, 2022 · 13 comments
Open

Add type hints to better understand source #91

NicoHood opened this issue Jun 16, 2022 · 13 comments

Comments

@NicoHood
Copy link

NicoHood commented Jun 16, 2022

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
@niccokunzmann
Copy link
Owner

niccokunzmann commented Jun 16, 2022 via email

@NicoHood
Copy link
Author

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

@NicoHood
Copy link
Author

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())

@niccokunzmann
Copy link
Owner

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

@niccokunzmann
Copy link
Owner

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'.

@NicoHood
Copy link
Author

@niccokunzmann
Copy link
Owner

niccokunzmann commented Jun 22, 2022

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?

@NicoHood
Copy link
Author

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.

@NicoHood
Copy link
Author

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

@niccokunzmann
Copy link
Owner

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.

@niccokunzmann
Copy link
Owner

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

@NicoHood
Copy link
Author

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.

@niccokunzmann
Copy link
Owner

niccokunzmann commented Jan 19, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants