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

Drop compat wrapper for TimeDelta.total_seconds() #5577

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@ def unicode_http_header(value):
return value


def total_seconds(timedelta):
# TimeDelta.total_seconds() is only available in Python 2.7
if hasattr(timedelta, 'total_seconds'):
return timedelta.total_seconds()
else:
return (timedelta.days * 86400.0) + float(timedelta.seconds) + (timedelta.microseconds / 1000000.0)


def distinct(queryset, base):
if settings.DATABASES[queryset.db]["ENGINE"] == "django.db.backends.oracle":
# distinct analogue for Oracle users
Expand Down
4 changes: 2 additions & 2 deletions rest_framework/utils/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.utils.encoding import force_text
from django.utils.functional import Promise

from rest_framework.compat import coreapi, total_seconds
from rest_framework.compat import coreapi


class JSONEncoder(json.JSONEncoder):
Expand All @@ -39,7 +39,7 @@ def default(self, obj):
representation = obj.isoformat()
return representation
elif isinstance(obj, datetime.timedelta):
return six.text_type(total_seconds(obj))
return six.text_type(obj.total_seconds())
elif isinstance(obj, decimal.Decimal):
# Serializers will coerce decimals to strings by default.
return float(obj)
Expand Down
9 changes: 0 additions & 9 deletions tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ def tearDown(self):
compat.django.VERSION = self.original_django_version
compat.transaction = self.original_transaction

def test_total_seconds(self):
class MockTimedelta(object):
days = 1
seconds = 1
microseconds = 100
timedelta = MockTimedelta()
expected = (timedelta.days * 86400.0) + float(timedelta.seconds) + (timedelta.microseconds / 1000000.0)
assert compat.total_seconds(timedelta) == expected

def test_set_rollback_for_transaction_in_managed_mode(self):
class MockTransaction(object):
called_rollback = False
Expand Down