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

Possible bug when using datetime for default arguments #14

Open
NikosAlexandris opened this issue Dec 1, 2020 · 1 comment
Open

Possible bug when using datetime for default arguments #14

NikosAlexandris opened this issue Dec 1, 2020 · 1 comment

Comments

@NikosAlexandris
Copy link
Contributor

NikosAlexandris commented Dec 1, 2020

The following default arguments might be a problem:

start_date: datetime = date.today()-timedelta(days=365),
end_date: datetime = date.today(),

Default arguments are evaluated at import time. If importing is performed at 23:59 in an interactive session, then running the script at 00:01, a day will be missing from the results. Likewise in a long running script which might start at 23.40 and fetch() gets to run after 00:00.

Suggested solution

def foo(start_date = None):
    if start_date is None:
        start_date = datetime.today() - timedelta(days=365)

or make these mandatory arguments.

(Kindly suggested by https://github.com/pmav99)

@dimartinot
Copy link
Owner

This is a very good suggestion, I will work into it.

Thanks,

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