@@ -61,7 +61,7 @@ def render_verbalizer(verbalizer_template: str, source_object) -> str:
6161 {{output}} with getattr(source_object, "target").
6262 returns: "Source: machine Target: learning"
6363
64- NOTE: This function will throw KeyError/AttributeError if you try to grab a key or property
64+ NOTE: This function will throw ValueError if you try to grab a key or property
6565 that is invalid.
6666
6767 Args:
@@ -74,7 +74,7 @@ def render_verbalizer(verbalizer_template: str, source_object) -> str:
7474 """
7575 is_dict = isinstance (source_object , dict )
7676
77- def replace_text (match_obj ):
77+ def replace_text (match_obj : re . Match ):
7878 captured_groups = match_obj .groups ()
7979 if len (captured_groups ) != 1 :
8080 error (
@@ -89,15 +89,17 @@ def replace_text(match_obj):
8989 if index_object not in source_object :
9090 error (
9191 "<NLP97415192E>" ,
92- KeyError ("Requested template string is not a valid key in dict" ),
92+ ValueError (
93+ f"Requested template string '{ index_object } ' is not a valid key in dict"
94+ ),
9395 )
9496 return source_object [index_object ]
9597
9698 if not hasattr (source_object , index_object ):
9799 error (
98100 "<NLP97715112E>" ,
99- AttributeError (
100- "Requested template string is not a valid property of type"
101+ ValueError (
102+ f "Requested template string ' { index_object } ' is not a valid property of type",
101103 ),
102104 )
103105 return getattr (source_object , index_object )
0 commit comments