From 4afeb050bfd0034c59d12d905a96b6c04350c318 Mon Sep 17 00:00:00 2001 From: ya7010 Date: Wed, 2 Jul 2025 16:24:56 +0900 Subject: [PATCH] refactor: remove hardcoded dimensions in simple_example.py and update PictureProps to use TypedDict for better type safety --- examples/simple_example.py | 2 -- src/tppt/pptx/shape/picture.py | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/simple_example.py b/examples/simple_example.py index 7e05079..6a7d3a3 100644 --- a/examples/simple_example.py +++ b/examples/simple_example.py @@ -63,8 +63,6 @@ def main(): EXAMPLE_DIR / "images" / "python-logo.png", left=(50, "pt"), top=(100, "pt"), - width=(300, "pt"), - height=(80, "pt"), ) .text( "The Python logo", diff --git a/src/tppt/pptx/shape/picture.py b/src/tppt/pptx/shape/picture.py index 6a5af5b..a64477d 100644 --- a/src/tppt/pptx/shape/picture.py +++ b/src/tppt/pptx/shape/picture.py @@ -1,17 +1,22 @@ -from typing import IO, Literal, NotRequired, assert_never +from typing import IO, Literal, NotRequired, TypedDict, assert_never from pptx.opc.constants import CONTENT_TYPE from pptx.shapes.picture import Movie as PptxMovie from pptx.shapes.picture import Picture as PptxPicture -from tppt.types import FilePath +from tppt.types import FilePath, Length, LiteralLength from . import BaseShape, RangeProps -class PictureProps(RangeProps): +class PictureProps(TypedDict): """Picture properties.""" + left: Length | LiteralLength + top: Length | LiteralLength + width: NotRequired[Length | LiteralLength] + height: NotRequired[Length | LiteralLength] + class PictureData(PictureProps): """Picture data."""