|
18 | 18 | from django.utils.functional import LazyObject, Promise |
19 | 19 | from django.utils.version import PY311, get_docs_version |
20 | 20 |
|
| 21 | +FUNCTION_TYPES = (types.FunctionType, types.BuiltinFunctionType, types.MethodType) |
| 22 | + |
| 23 | +if isinstance(functools._lru_cache_wrapper, type): |
| 24 | + # When using CPython's _functools C module, LRU cache function decorators |
| 25 | + # present as a class and not a function, so add that class to the list of |
| 26 | + # function types. In the pure Python implementation and PyPy they present |
| 27 | + # as normal functions which are already handled. |
| 28 | + FUNCTION_TYPES += (functools._lru_cache_wrapper,) |
| 29 | + |
21 | 30 |
|
22 | 31 | class BaseSerializer: |
23 | 32 | def __init__(self, value): |
@@ -346,12 +355,7 @@ class Serializer: |
346 | 355 | (bool, int, types.NoneType, bytes, str, range): BaseSimpleSerializer, |
347 | 356 | decimal.Decimal: DecimalSerializer, |
348 | 357 | (functools.partial, functools.partialmethod): FunctoolsPartialSerializer, |
349 | | - ( |
350 | | - types.FunctionType, |
351 | | - types.BuiltinFunctionType, |
352 | | - types.MethodType, |
353 | | - functools._lru_cache_wrapper, |
354 | | - ): FunctionTypeSerializer, |
| 358 | + FUNCTION_TYPES: FunctionTypeSerializer, |
355 | 359 | collections.abc.Iterable: IterableSerializer, |
356 | 360 | (COMPILED_REGEX_TYPE, RegexObject): RegexSerializer, |
357 | 361 | uuid.UUID: UUIDSerializer, |
|
0 commit comments