You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One issue with using constants on a module is if someone uses compressionLevel in place of windowLogMax when passed to the decompressor, that won't be caught. They are both C enum variants with value 100. For that reason I am leaning towards keeping CParameter/DParameter.
One possible workaround would be wrapping the constants in zstd with newtypes, i.e.
classCParameter(int):
"""Newtype to mark a value as a compression parameter"""compressionLevel=CParameter(compressionLevel)
...
Then the module state would keep the CParameter/DParameter types, and use that to check compression vs decompression parameters.
FWIW at this point I think it would be better to keep things as they are and maybe export the CParameter attributes at the module level, e.g.
# in compression.zstd modulecompressionLevel=CParameter.compressionLevel
That makes the API simpler to use but keeps the existing known working code :)
Activity
Rogdham commentedon Apr 18, 2025
I would be slightly in favor of converting into constants on the module, solely because this is what existing modules (e.g. lzma) are doing already.
emmatyping commentedon Apr 24, 2025
One issue with using constants on a module is if someone uses
compressionLevelin place ofwindowLogMaxwhen passed to the decompressor, that won't be caught. They are both C enum variants with value 100. For that reason I am leaning towards keeping CParameter/DParameter.One possible workaround would be wrapping the constants in
zstdwith newtypes, i.e.Then the module state would keep the CParameter/DParameter types, and use that to check compression vs decompression parameters.
FWIW at this point I think it would be better to keep things as they are and maybe export the
CParameterattributes at the module level, e.g.That makes the API simpler to use but keeps the existing known working code :)