File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -75,13 +75,28 @@ class MySlideLayout(TpptSlideLayout):
7575 text : Annotated [str , Placeholder ]
7676
7777
78- def get_placeholders (slide : type [TpptSlideLayout ]) -> dict [str , Any ]:
79- """クラスのメタ情報を解析し、プレースホルダーのフィールドのキーバリューを取得する"""
80- return slide .__placeholders__
78+ def get_placeholders (
79+ slide_or_class : type [TpptSlideLayout ] | TpptSlideLayout ,
80+ ) -> dict [str , Any ]:
81+ """クラスのメタ情報を解析し、プレースホルダーのフィールドのキーバリューを取得する
82+
83+ 引数にインスタンスが渡された場合は、実際のプレースホルダー値を返す
84+ クラスが渡された場合は、プレースホルダーの型情報を返す
85+ """
86+ if isinstance (slide_or_class , type ):
87+ # クラスが渡された場合は型情報を返す
88+ return slide_or_class .__placeholders__
89+ else :
90+ # インスタンスの場合は実際の値を返す
91+ values = {}
92+ for field_name in slide_or_class .__class__ .__placeholders__ :
93+ if hasattr (slide_or_class , field_name ):
94+ values [field_name ] = getattr (slide_or_class , field_name )
95+ return values
8196
8297
8398# TODO: 以下のアサーションが通るようにせよ
8499Myslide : type [TpptSlideLayout ] = MySlideLayout
85100myslide = Myslide (title = "a" , text = "b" )
86101
87- assert get_placeholders (Myslide ) == {"title" : "a" , "text" : "b" }
102+ assert get_placeholders (myslide ) == {"title" : "a" , "text" : "b" }
You can’t perform that action at this time.
0 commit comments