Skip to content

Commit

Permalink
Merge pull request #8165 from radarhere/imagedraw2_error
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Jun 24, 2024
2 parents fb722a3 + e5c4d56 commit ad4c23b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Tests/test_imagedraw2.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def test_sanity() -> None:
draw2.line(list(range(10)), pen)


def test_mode() -> None:
draw = ImageDraw2.Draw("L", (1, 1))
assert draw.image.mode == "L"

with pytest.raises(ValueError):
ImageDraw2.Draw("L")


@pytest.mark.parametrize("bbox", BBOX)
def test_ellipse(bbox: Coords) -> None:
# Arrange
Expand Down
12 changes: 10 additions & 2 deletions src/PIL/ImageDraw2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ class Draw:
(Experimental) WCK-style drawing interface
"""

def __init__(self, image, size=None, color=None):
if not hasattr(image, "im"):
def __init__(
self,
image: Image.Image | str,
size: tuple[int, int] | list[int] | None = None,
color: float | tuple[float, ...] | str | None = None,
) -> None:
if isinstance(image, str):
if size is None:
msg = "If image argument is mode string, size must be a list or tuple"
raise ValueError(msg)
image = Image.new(image, size, color)
self.draw = ImageDraw.Draw(image)
self.image = image
Expand Down

0 comments on commit ad4c23b

Please sign in to comment.