mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	It turns out that `functools._lru_cache_wrapper` is only a class when CPython's _functools C module provides it, otherwise it is a function. PyPy also provides it as a function.
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							76280b4f4d
						
					
				
				
					commit
					5f9e5c1b0d
				
			| @@ -18,6 +18,15 @@ from django.db.migrations.utils import COMPILED_REGEX_TYPE, RegexObject | |||||||
| from django.utils.functional import LazyObject, Promise | from django.utils.functional import LazyObject, Promise | ||||||
| from django.utils.version import PY311, get_docs_version | from django.utils.version import PY311, get_docs_version | ||||||
|  |  | ||||||
|  | FUNCTION_TYPES = (types.FunctionType, types.BuiltinFunctionType, types.MethodType) | ||||||
|  |  | ||||||
|  | if isinstance(functools._lru_cache_wrapper, type): | ||||||
|  |     # When using CPython's _functools C module, LRU cache function decorators | ||||||
|  |     # present as a class and not a function, so add that class to the list of | ||||||
|  |     # function types. In the pure Python implementation and PyPy they present | ||||||
|  |     # as normal functions which are already handled. | ||||||
|  |     FUNCTION_TYPES += (functools._lru_cache_wrapper,) | ||||||
|  |  | ||||||
|  |  | ||||||
| class BaseSerializer: | class BaseSerializer: | ||||||
|     def __init__(self, value): |     def __init__(self, value): | ||||||
| @@ -346,12 +355,7 @@ class Serializer: | |||||||
|         (bool, int, types.NoneType, bytes, str, range): BaseSimpleSerializer, |         (bool, int, types.NoneType, bytes, str, range): BaseSimpleSerializer, | ||||||
|         decimal.Decimal: DecimalSerializer, |         decimal.Decimal: DecimalSerializer, | ||||||
|         (functools.partial, functools.partialmethod): FunctoolsPartialSerializer, |         (functools.partial, functools.partialmethod): FunctoolsPartialSerializer, | ||||||
|         ( |         FUNCTION_TYPES: FunctionTypeSerializer, | ||||||
|             types.FunctionType, |  | ||||||
|             types.BuiltinFunctionType, |  | ||||||
|             types.MethodType, |  | ||||||
|             functools._lru_cache_wrapper, |  | ||||||
|         ): FunctionTypeSerializer, |  | ||||||
|         collections.abc.Iterable: IterableSerializer, |         collections.abc.Iterable: IterableSerializer, | ||||||
|         (COMPILED_REGEX_TYPE, RegexObject): RegexSerializer, |         (COMPILED_REGEX_TYPE, RegexObject): RegexSerializer, | ||||||
|         uuid.UUID: UUIDSerializer, |         uuid.UUID: UUIDSerializer, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user