1
0
mirror of https://github.com/django/django.git synced 2025-03-06 15:32:33 +00:00

[5.2.x] Clarified cryptic comment in django/core/cache/backends/redis.py.

Backport of 9a729fb61add16d89a4b42b491aec2d22f1ae69a from main.
This commit is contained in:
Tim Graham 2025-03-05 20:02:23 -05:00 committed by Natalia
parent d42b187022
commit b179c67860

View File

@ -14,8 +14,9 @@ class RedisSerializer:
self.protocol = pickle.HIGHEST_PROTOCOL if protocol is None else protocol self.protocol = pickle.HIGHEST_PROTOCOL if protocol is None else protocol
def dumps(self, obj): def dumps(self, obj):
# Only skip pickling for integers, a int subclasses as bool should be # For better incr() and decr() atomicity, don't pickle integers.
# pickled. # Using type() rather than isinstance() matches only integers and not
# subclasses like bool.
if type(obj) is int: if type(obj) is int:
return obj return obj
return pickle.dumps(obj, self.protocol) return pickle.dumps(obj, self.protocol)