Skip to content

Commit 0e308ce

Browse files
committed
fix: update __getattr__ method to raise AttributeError for non-existent attributes
1 parent 0f71c8e commit 0e308ce

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

design/slide_master.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
class TpptSlideMasterMeta(type):
77
"""TpptSlideMasterのメタクラス"""
88

9-
def __getattr__(self, key: str) -> Any:
9+
def __getattr__(self, key: str) -> "type[TpptSlideLayout]":
1010
if key in self.__annotations__:
1111
annotation = self.__annotations__[key]
1212
if issubclass(annotation, TpptSlideLayout):
1313
return annotation
1414
else:
1515
raise AttributeError(f"属性 {key}{annotation} ではありません")
1616

17+
raise AttributeError(f"属性 {key} は存在しません")
1718

1819
@dataclass_transform(
1920
eq_default=True,
@@ -55,7 +56,8 @@ def __get__(self, instance: object | None, objtype: type[Any]) -> type[Self] | S
5556
TpptSlideLayoutType = TypeVar("TpptSlideLayoutType", bound=Type[TpptSlideLayout])
5657

5758

58-
class MyMasterSlide(TpptSlideLayout): ...
59+
class MyMasterSlide(TpptSlideLayout):
60+
def __init__(self, a: int, b: str): ...
5961

6062

6163
class MyTitleSlide(TpptSlideLayout): ...
@@ -75,3 +77,4 @@ class MySlideMaster(TpptSlideMaster):
7577
assert MySlideMaster.master == MyMasterSlide
7678
assert MySlideMaster.title == MyTitleSlide
7779
assert MySlideMaster.totle_and_content == MyContentSlide
80+
MySlideMaster.master(a=1, b="a")

0 commit comments

Comments
 (0)