Skip to content

Commit b044571

Browse files
committed
refactor: update SubShape class to use generic type for improved type safety
1 parent 0df4b4f commit b044571

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/tppt/pptx/shape/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,22 @@ def text_frame(self) -> "TextFrame":
5858
return TextFrame(self._pptx.text_frame)
5959

6060

61-
class SubShape(PptxConvertible[PptxSubshape]):
62-
def __init__(self, pptx_shape: PptxSubshape) -> None:
63-
self._pptx: PptxSubshape = pptx_shape
61+
_GenericPptxSubshape = TypeVar("_GenericPptxSubshape", bound=PptxSubshape)
62+
63+
64+
class SubShape(PptxConvertible[_GenericPptxSubshape]):
65+
def __init__(self, pptx_shape: _GenericPptxSubshape) -> None:
66+
self._pptx: _GenericPptxSubshape = pptx_shape
6467

6568
@property
6669
def part(self) -> XmlPart:
6770
return self._pptx.part
6871

69-
def to_pptx(self) -> PptxSubshape:
72+
def to_pptx(self) -> _GenericPptxSubshape:
7073
return self._pptx
7174

7275
@classmethod
73-
def from_pptx(cls, pptx_obj: PptxSubshape) -> Self:
76+
def from_pptx(cls, pptx_obj: _GenericPptxSubshape) -> Self:
7477
return cls(pptx_obj)
7578

7679

src/tppt/pptx/text/text_frame.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from typing import Self
2-
31
from pptx.enum.text import MSO_AUTO_SIZE, MSO_VERTICAL_ANCHOR
42
from pptx.text.text import TextFrame as PptxTextFrame
53
from pptx.util import Length as PptxLength
64

7-
from tppt.pptx.converter import PptxConvertible, to_pptx_length
5+
from tppt.pptx.converter import to_pptx_length
6+
from tppt.pptx.shape import SubShape
87
from tppt.pptx.text.paragraph import Paragraph
98
from tppt.types._length import EnglishMetricUnits, Length, LiteralLength, to_emu
109

1110

12-
class TextFrame(PptxConvertible[PptxTextFrame]):
11+
class TextFrame(SubShape[PptxTextFrame]):
1312
def __init__(self, pptx_obj: PptxTextFrame) -> None:
14-
self._pptx = pptx_obj
13+
super().__init__(pptx_obj)
1514

1615
def add_paragraph(self) -> Paragraph:
1716
return Paragraph(self._pptx.add_paragraph())
@@ -96,10 +95,3 @@ def word_wrap(self) -> bool | None:
9695
@word_wrap.setter
9796
def word_wrap(self, value: bool | None) -> None:
9897
self._pptx.word_wrap = value
99-
100-
def to_pptx(self) -> PptxTextFrame:
101-
return self._pptx
102-
103-
@classmethod
104-
def from_pptx(cls, pptx_obj: PptxTextFrame) -> Self:
105-
return cls(pptx_obj)

0 commit comments

Comments
 (0)