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

Fix tick delta type handling #546

Merged
merged 6 commits into from
May 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions freezegun/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ def __init__(self, time_to_freeze: datetime.datetime):
def __call__(self) -> datetime.datetime:
return self.time_to_freeze

def tick(self, delta: Union[datetime.timedelta, int]=datetime.timedelta(seconds=1)) -> datetime.datetime:
if isinstance(delta, numbers.Real):
def tick(self, delta: Union[datetime.timedelta, float]=datetime.timedelta(seconds=1)) -> datetime.datetime:
if isinstance(delta, float):
robsdedude marked this conversation as resolved.
Show resolved Hide resolved
# noinspection PyTypeChecker
self.time_to_freeze += datetime.timedelta(seconds=delta)
else:
Expand All @@ -557,9 +557,11 @@ def __call__(self) -> datetime.datetime:
self.tick()
return return_time

def tick(self, delta: Union[datetime.timedelta, int, None]=None) -> datetime.datetime:
def tick(self, delta: Union[datetime.timedelta, float, None]=None) -> datetime.datetime:
if not delta:
delta = datetime.timedelta(seconds=self.step_width)
elif isinstance(delta, float):
robsdedude marked this conversation as resolved.
Show resolved Hide resolved
delta = datetime.timedelta(seconds=delta)
self.time_to_freeze += delta # type: ignore
return self.time_to_freeze

Expand Down
Loading