Skip to content

Commit 3be3a5c

Browse files
committed
Clarify chain pre-check rationale in materialization helpers
Document why `_materialize_method_segment` and `_materialize_property_segment` perform strict-independent pre-checks before creating stubs. The comments also point readers to strict/spec validation in `StubbedInvocation.__call__` and `StubbedPropertyAccess.__call__`.
1 parent 187a675 commit 3be3a5c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

mockito/mocking.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def _materialize_method_segment(
152152
kwargs: dict[str, Any],
153153
) -> Segment:
154154
if not chain.segments:
155+
# Pre-checks here are strict-independent and validate fluent-DSL
156+
# *shape* (e.g. call-vs-attribute intent) before we patch anything.
157+
# Strict/spec validation remains in StubbedInvocation.__call__
158+
# (`ensure_mocked_object_has_method` + signature checks).
155159
_ensure_target_is_callable(chain.theMock, name)
156160

157161
invoc = invocation.StubbedInvocation(chain.theMock, name, **chain.options)
@@ -176,6 +180,10 @@ def _materialize_property_segment(
176180
name: str,
177181
) -> Segment:
178182
if not chain.segments:
183+
# Same rationale as method materialization above: these pre-checks are
184+
# strict-independent API-shape guards for property-style stubbing.
185+
# Strict/spec checks for property stubs live in
186+
# StubbedPropertyAccess.__call__ (`ensure_mocked_object_has_attribute`).
179187
_ensure_target_is_not_callable(chain.theMock, name)
180188

181189
if not inspect.isclass(chain.theMock.mocked_obj):

0 commit comments

Comments
 (0)