fix: defer validation for unresolved conditional branches#701
fix: defer validation for unresolved conditional branches#701Stefanqn wants to merge 4 commits intoreagento:developfrom
Conversation
|
Actually, I would check as much as possible at graph building stage. Probably, we should have a toggle to enable this behavior |
c9e3f73 to
481ce05
Compare
|
both is fine for me |
|
Looks like we have 2 options here:
|
|
like that? |
6e4f4d9 to
8b5b95c
Compare
|
I also added a toggle per factory in my latest commit Should alias(...) and from_context(...) support the same override as well? |
|
Isn't per factory setting too much? Do we have any UseCase for that? |
|
if it's too much, drop the last commit :) |
|
Can I accelerate merging any kind of bugfix for |
|
Do you have any particular usecase for this specific PR? I am not sure if I am satisfied with the API changes here though it has some sense here. Do you need this together with #696 at this moment? |
|
In terms of configuring validation is see these cases:
For me it is not clear how should we let user decide whether to skip checks. In #696 I went with simple logic: cases 1,2,3 disable validation, others are always validated. |
0071abd to
3a593fb
Compare
|
|
#696 still fails the valid use case of 1 "a" False in @pytest.mark.parametrize( ("number", "expected", "raises"), [
(1, "a", False),
(0, None, True),
])
def test_unresolved_conditional_branch_is_validated_at_runtime(
*,
number: int,
expected: str | None,
raises: bool,
):
provider = Provider(scope=Scope.APP)
provider.activate(is_zero, Marker("ZERO"))
provider.provide(lambda: number, provides=int)
provider.provide(fallback, provides=str)
provider.provide(needs_float, provides=str, when=Marker("ZERO"))
container = make_container(provider)
if raises:
with pytest.raises(NoFactoryError):
container.get(str)
else:
assert container.get(str) == expectedI see the validation as a guardrail. If we don't lower the bar, so that arbitrary activation logic isn't validated, false positives seem inevitable (I doubt we can properly validate arbitrary activation logic). Because false positives can block legit code, the only option I see is to provide a toggle to disable validation in that case. Please inspect following tests in my PR:
|
I do not see this as a good way for providing constants. We should either recommend using For arbitrary factories it is not possible if they produce the same value every time. We allow calling |
I agree, but personally I think
|
|
Another possible option: allow specific factories to be called on static evaluation step. |



No description provided.