1
0
mirror of https://github.com/django/django.git synced 2025-04-10 08:19:39 +00:00

Remove unused util method

This commit is contained in:
Jake Howard 2024-10-17 10:03:59 +01:00
parent 499d040b0b
commit fef3662e5d
No known key found for this signature in database
GPG Key ID: 57AFB45680EDD477
2 changed files with 0 additions and 29 deletions

View File

@ -1,7 +1,6 @@
import inspect
import json
import time
from collections import deque
from functools import wraps
from traceback import format_exception
@ -18,18 +17,6 @@ def is_global_function(func):
return True
def is_json_serializable(obj):
"""
Determine, as efficiently as possible, whether an object is JSON-serializable.
"""
try:
# HACK: JSON-encode an object, without loading it all into memory
deque(json.JSONEncoder().iterencode(obj), maxlen=0)
return True
except (TypeError, OverflowError):
return False
def json_normalize(obj):
"""
Round-trip encode object as JSON to normalize types.

View File

@ -48,22 +48,6 @@ class IsGlobalFunctionTestCase(SimpleTestCase):
self.assertFalse(is_global_function_fixture.inner_func_is_global_function)
class IsJSONSerializableTestCase(SimpleTestCase):
def test_serializable(self):
for example in [123, 12.3, "123", {"123": 456}, [], None]:
with self.subTest(example):
self.assertTrue(utils.is_json_serializable(example))
def test_not_serializable(self):
for example in [
self,
any,
datetime.datetime.now(),
]:
with self.subTest(example):
self.assertFalse(utils.is_json_serializable(example))
class JSONNormalizeTestCase(SimpleTestCase):
def test_round_trip(self):
self.assertEqual(utils.json_normalize({}), {})