Merge pull request #6917 from radarhere/register_open

Prevent register_open from adding duplicates to ID
This commit is contained in:
mergify[bot] 2023-01-28 12:34:45 +00:00 committed by GitHub
commit 30010c4fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -398,6 +398,17 @@ class TestImage:
with pytest.raises(ValueError):
source.alpha_composite(over, (0, 0), (0, -1))
def test_register_open_duplicates(self):
# Arrange
factory, accept = Image.OPEN["JPEG"]
id_length = len(Image.ID)
# Act
Image.register_open("JPEG", factory, accept)
# Assert
assert len(Image.ID) == id_length
def test_registered_extensions_uninitialized(self):
# Arrange
Image._initialized = 0

View File

@ -3406,7 +3406,8 @@ def register_open(id, factory, accept=None):
reject images having another format.
"""
id = id.upper()
ID.append(id)
if id not in ID:
ID.append(id)
OPEN[id] = factory, accept