File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change 13
13
14
14
logger = logging .getLogger (__name__ )
15
15
16
+
16
17
class ProgramMeta (type ):
17
18
"""Metaclass ensuring every ``dspy.Module`` instance is properly initialised."""
18
19
@@ -161,14 +162,16 @@ def batch(
161
162
def __getattribute__ (self , name ):
162
163
attr = super ().__getattribute__ (name )
163
164
164
- if name == ' forward' and callable (attr ):
165
- # Check if forward iscalled through __call__
165
+ if name == " forward" and callable (attr ):
166
+ # Check if forward is called through __call__ or directly
166
167
stack = inspect .stack ()
167
- called_via_call = len (stack ) > 1 and stack [1 ].function == ' __call__'
168
+ forward_called_directly = len (stack ) <= 1 or stack [1 ].function != " __call__"
168
169
169
- if not called_via_call :
170
- logger .warning (f"Calling { self .__class__ .__name__ } .forward() directly is discouraged. "
171
- f"Use { self .__class__ .__name__ } () instead." )
170
+ if forward_called_directly :
171
+ logger .warning (
172
+ f"Calling { self .__class__ .__name__ } .forward() directly is discouraged. "
173
+ f"Please use { self .__class__ .__name__ } () instead."
174
+ )
172
175
173
176
return attr
174
177
You can’t perform that action at this time.
0 commit comments