Failing test that should pass
A Template that synthesises a callable, called from a pytest test method, fails mypy validation in the synthesizer because the request fixture's type (_pytest.fixtures.TopRequest) is added to the context stubs but _pytest is never imported.
import pytest
from typing import Callable
from effectful.handlers.llm import Template
from effectful.handlers.llm.evaluation import UnsafeEvalProvider
from effectful.ops.semantics import handler
class TestSynthesisRegression:
@pytest.fixture(autouse=False)
def _dummy(self): yield
def test_synthesis_with_pytest_request_in_scope(self, request):
threshold = 0.85
@Template.define
def make() -> Callable[[float], bool]:
"""Use the `threshold` reader, then `def above(x: float) -> bool: return x > <value>`."""
raise NotImplementedError
with handler(UnsafeEvalProvider()):
fn = make() # currently raises ResultDecodingError
assert fn(0.9) is True
The LLM call itself succeeds and emits def above(x: float) -> bool: return x > 0.85. The failure surfaces inside mypy_type_check.
Root cause
effectful/handlers/llm/evaluation.py:251 collect_imports:
modules: set[tuple[str, str | None]] = set(
(k, None)
for k in sys.modules.keys()
if k not in SKIPPED_GLOBALS and not k.startswith("_") and k[0].isalpha()
)
The not k.startswith("_") clause filters out every module whose name begins with an underscore — including _pytest, which pytest's public surface re-exports types from. When collect_variable_declarations later emits a stub line like
request: _pytest.fixtures.TopRequest
(because the runtime request value's class is _pytest.fixtures.TopRequest), the qualified type name still references _pytest, but the import has been silently dropped. mypy then reports
<string>:17: error: Name "_pytest" is not defined [name-defined]
and mypy_type_check raises TypeError, which surfaces as ResultDecodingError.
Failing test that should pass
A Template that synthesises a callable, called from a pytest test method, fails mypy validation in the synthesizer because the
requestfixture's type (_pytest.fixtures.TopRequest) is added to the context stubs but_pytestis never imported.The LLM call itself succeeds and emits
def above(x: float) -> bool: return x > 0.85. The failure surfaces insidemypy_type_check.Root cause
effectful/handlers/llm/evaluation.py:251 collect_imports:The
not k.startswith("_")clause filters out every module whose name begins with an underscore — including_pytest, whichpytest's public surface re-exports types from. Whencollect_variable_declarationslater emits a stub line like(because the runtime
requestvalue's class is_pytest.fixtures.TopRequest), the qualified type name still references_pytest, but the import has been silently dropped. mypy then reportsand
mypy_type_checkraisesTypeError, which surfaces asResultDecodingError.