Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoders and encoders subclass PyDecoder and PyEncoder #7801

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

radarhere
Copy link
Member

register_decoder() and register_encoder() state that decoder/encoder are callables that return an object.

Pillow/src/PIL/Image.py

Lines 3527 to 3534 in 912a33f

def register_decoder(name: str, decoder) -> None:
"""
Registers an image decoder. This function should not be
used in application code.
:param name: The name of the decoder
:param decoder: A callable(mode, args) that returns an
ImageFile.PyDecoder object

Pillow/src/PIL/Image.py

Lines 3541 to 3548 in 912a33f

def register_encoder(name, encoder):
"""
Registers an image encoder. This function should not be
used in application code.
:param name: The name of the encoder
:param encoder: A callable(mode, args) that returns an
ImageFile.PyEncoder object

However, if you look at Pillow's source code, it is not a callable, it is just an object.

Image.register_decoder("BLP1", BLP1Decoder)
Image.register_decoder("BLP2", BLP2Decoder)
Image.register_save(BlpImageFile.format, _save)
Image.register_encoder("BLP", BLPEncoder)

Image.register_decoder("ppm", PpmDecoder)
Image.register_decoder("ppm_plain", PpmPlainDecoder)

Image.register_decoder("dds_rgb", DdsRgbDecoder)

Image.register_decoder("SGI16", SGI16Decoder)

This PR updates the docstrings, clarifies this by adding type hints, and updates the tests (which did treat the arguments as callables).

@radarhere radarhere changed the title Decoder and encoders subclass PyDecoder and PyEncoder Decoders and encoders subclass PyDecoder and PyEncoder Feb 15, 2024
@hugovk hugovk merged commit 3cdd49f into python-pillow:main Mar 11, 2024
56 checks passed
@radarhere radarhere deleted the codecs branch March 12, 2024 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants