@@ -16,11 +16,17 @@ def register_class_attribute(attribute_name: str, value: Any) -> None:
1616 attribute_name: The name of the attribute to set on the class
1717 value: The value to set for the attribute
1818 """
19- frame = inspect .currentframe ()
20- if frame and frame .f_back and frame .f_back .f_back :
21- caller_locals = frame .f_back .f_back .f_locals
22- if "__module__" in caller_locals and "__qualname__" in caller_locals :
23- caller_locals [attribute_name ] = value
19+ try :
20+ frame = inspect .currentframe ()
21+ if frame and frame .f_back and frame .f_back .f_back :
22+ caller_locals = frame .f_back .f_back .f_locals
23+ if (
24+ "__module__" in caller_locals
25+ and "__qualname__" in caller_locals
26+ ):
27+ caller_locals [attribute_name ] = value
28+ except (AttributeError , KeyError ):
29+ pass
2430
2531
2632def append_to_class_list (list_name : str , value : Any ) -> None :
@@ -36,10 +42,16 @@ def append_to_class_list(list_name: str, value: Any) -> None:
3642 list_name: The name of the list attribute on the class
3743 value: The value to append to the list
3844 """
39- frame = inspect .currentframe ()
40- if frame and frame .f_back and frame .f_back .f_back :
41- caller_locals = frame .f_back .f_back .f_locals
42- if "__module__" in caller_locals and "__qualname__" in caller_locals :
43- if list_name not in caller_locals :
44- caller_locals [list_name ] = []
45- caller_locals [list_name ].append (value )
45+ try :
46+ frame = inspect .currentframe ()
47+ if frame and frame .f_back and frame .f_back .f_back :
48+ caller_locals = frame .f_back .f_back .f_locals
49+ if (
50+ "__module__" in caller_locals
51+ and "__qualname__" in caller_locals
52+ ):
53+ if list_name not in caller_locals :
54+ caller_locals [list_name ] = []
55+ caller_locals [list_name ].append (value )
56+ except (AttributeError , KeyError ):
57+ pass
0 commit comments