@@ -242,14 +242,12 @@ def calc_hash(first: ty.Optional[bytes] = None) -> Hash:
242
242
h .update (chunk )
243
243
return Hash (h .digest ())
244
244
245
- # Read the first chunk of the bytes_repr iterator, check to see whether it returns
246
- # a "cache-key" tuple instead of a bytes chunk for the type of the object to cache
245
+ # Read the first item of the bytes_repr iterator, check to see whether it returns
246
+ # a "cache-key" tuple instead of a bytes chunk for the type of the object to be cached
247
247
# (i.e. file objects). If it does use that key to check the persistent cache for
248
- # a precomputed hash and otherwise calculate the hash and store it in the
249
- # persistent cache with that key.
250
-
251
- # If the first chunk is a bytes chunk (i.e. the object type doesn't have an associated
252
- # 'cache-key'), then simply calculate the hash of the object.
248
+ # a precomputed hash and return it if it is, otherwise calculate the hash and
249
+ # store it in the persistent cache with that hash of that key (not to be confused
250
+ # with the hash of the object that is saved/retrieved).
253
251
first = next (bytes_it )
254
252
if isinstance (first , tuple ):
255
253
tp = type (obj )
@@ -259,6 +257,10 @@ def calc_hash(first: ty.Optional[bytes] = None) -> Hash:
259
257
) + first
260
258
hsh = cache .persistent .get_or_calculate_hash (key , calc_hash )
261
259
else :
260
+ # If the first item is a bytes chunk (i.e. the object type doesn't have an
261
+ # associated 'cache-key'), then simply calculate the hash of the object,
262
+ # passing the first chunk to the `calc_hash` function so it can be included
263
+ # in the hash calculation
262
264
hsh = calc_hash (first = first )
263
265
logger .debug ("Hash of %s object is %s" , obj , hsh )
264
266
cache [objid ] = hsh
0 commit comments