Skip to content

Commit 6e6c378

Browse files
Small style fix (#8381)
1 parent 7d675c9 commit 6e6c378

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

dspy/primitives/program.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
logger = logging.getLogger(__name__)
1515

16+
1617
class ProgramMeta(type):
1718
"""Metaclass ensuring every ``dspy.Module`` instance is properly initialised."""
1819

@@ -161,14 +162,16 @@ def batch(
161162
def __getattribute__(self, name):
162163
attr = super().__getattribute__(name)
163164

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
166167
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__"
168169

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+
)
172175

173176
return attr
174177

0 commit comments

Comments
 (0)