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

Remove unnecessary add/sub overrides on newer Pythons #417

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
54 changes: 28 additions & 26 deletions freezegun/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,21 @@ def date_to_fakedate(date):


class FakeDate(real_date, metaclass=FakeDateMeta):
def __add__(self, other):
result = real_date.__add__(self, other)
if result is NotImplemented:
return result
return date_to_fakedate(result)

def __sub__(self, other):
result = real_date.__sub__(self, other)
if result is NotImplemented:
return result
if isinstance(result, real_date):
if sys.version_info < (3, 8):
def __add__(self, other):
result = real_date.__add__(self, other)
if result is NotImplemented:
return result
return date_to_fakedate(result)
else:
return result

def __sub__(self, other):
result = real_date.__sub__(self, other)
if result is NotImplemented:
return result
if isinstance(result, real_date):
return date_to_fakedate(result)
else:
return result

@classmethod
def today(cls):
Expand Down Expand Up @@ -348,20 +349,21 @@ def __subclasscheck__(cls, subclass):


class FakeDatetime(real_datetime, FakeDate, metaclass=FakeDatetimeMeta):
def __add__(self, other):
result = real_datetime.__add__(self, other)
if result is NotImplemented:
return result
return datetime_to_fakedatetime(result)

def __sub__(self, other):
result = real_datetime.__sub__(self, other)
if result is NotImplemented:
return result
if isinstance(result, real_datetime):
if sys.version_info < (3, 8):
def __add__(self, other):
result = real_datetime.__add__(self, other)
if result is NotImplemented:
return result
return datetime_to_fakedatetime(result)
else:
return result

def __sub__(self, other):
result = real_datetime.__sub__(self, other)
if result is NotImplemented:
return result
if isinstance(result, real_datetime):
return datetime_to_fakedatetime(result)
else:
return result

def astimezone(self, tz=None):
if tz is None:
Expand Down