In this code that uses zlib to encode some data, but with level=0 so it's not actually compressed:
import zlib
print('zlib.ZLIB_VERSION', zlib.ZLIB_VERSION)
total = 0
print('Total 1', total)
compress_obj = zlib.compressobj(level=0, memLevel=9, wbits=-zlib.MAX_WBITS)
total += len(compress_obj.compress(b'-' * 1000000))
print('Total 2', total)
total += len(compress_obj.flush())
print('Total 3', total)
Python 3.9.12 outputs
zlib.ZLIB_VERSION 1.2.12
Total 1 0
Total 2 983068
Total 3 1000080
but Python 3.10.6 (and Python 3.11.0) outputs
zlib.ZLIB_VERSION 1.2.13
Total 1 0
Total 2 1000080
Total 3 1000085
so both a different final size, and a different size along the way.
Why? And how can I get them to be identical? (I'm writing a library where I would prefer identical behaviour between Python versions)