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
Calling Image.register_open multiply times should not lead to growth of Image.ID list.
What did you expect to happen?
After second call to Image.register_openImage.ID should not contain similar values.
What are your OS, Python and Pillow versions?
OS: not OS dependent
Python: not python version dependent
Pillow: 9.4.0
Maybe it is invalid usage, I know that applications should not call Image.register_open, but this very small problem present.
defregister_open(id, factory, accept=None):
""" Register an image file plugin. This function should not be used in application code. :param id: An image format identifier. :param factory: An image file factory method. :param accept: An optional function that can be used to quickly reject images having another format. """id=id.upper()
ID.append(id) # growth of the list here.OPEN[id] =factory, accept
Image.ID used only in a few places:
PIL.Image.open
ifformatsisNone:
formats=ID
PIL.FitsStubImagePlugin
# Override FitsImagePlugin with this handler# for backwards compatibilitytry:
Image.ID.remove(FITSStubImageFile.format)
exceptValueError:
passImage.register_open(
FITSStubImageFile.format, FITSStubImageFile, FitsImagePlugin._accept
)
Probably in 1 and 3 places this can be replaced with OPEN.keys() that contain the same values, if I understand code correct, and in place with number 2 just remove Image.ID.remove lines.
These changes should not affect performance.
The text was updated successfully, but these errors were encountered:
radarhere
changed the title
Image.register_open called multiply times
Image.register_open called multiple times
Jan 28, 2023
To be clear - you didn't actually have code that you'd written that you found calling Image.register_open multiple times, right? This is just a theoretical concern?
I'm reluctant to make ID redundant by replacing it with OPEN.keys(), since ID is part of the public API.
I've created PR #6917 to simply not append existing ids to ID.
To be clear - you didn't actually have code that you'd written that you found calling Image.register_open multiple times, right? This is just a theoretical concern?
Yes, it is more theoretical, you are right.
I've created PR #6917 to simply not append existing ids to ID.
What did you do?
Calling
Image.register_open
multiply times should not lead to growth ofImage.ID
list.What did you expect to happen?
After second call to
Image.register_open
Image.ID
should not contain similar values.What are your OS, Python and Pillow versions?
Maybe it is invalid usage, I know that applications should not call
Image.register_open
, but this very small problem present.Image.ID used only in a few places:
Probably in 1 and 3 places this can be replaced with
OPEN.keys()
that contain the same values, if I understand code correct, and in place with number 2 just removeImage.ID.remove
lines.These changes should not affect performance.
The text was updated successfully, but these errors were encountered: