Skip to content

Commit 61638ad

Browse files
bartvclaude
andcommitted
Fix mypy: type checked_args_cache as list[Optional[CheckedArgs]]
The cache was typed as list[object], causing mypy attr-defined errors when accessing .args/.kwargs on the cached value. Use proper CheckedArgs type and extract to a local variable for mypy narrowing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f9b357a commit 61638ad

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/inmanta/ast/statements/call.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import inmanta.ast.type as InmantaType
2626
import inmanta.execute.dataflow as dataflow
2727
from inmanta import plugins
28+
from inmanta.plugins import CheckedArgs
2829
from inmanta.ast import (
2930
ExplicitPluginException,
3031
ExternalException,
@@ -138,7 +139,7 @@ def execute_call(
138139
queue: QueueScheduler,
139140
result: ResultVariable,
140141
*,
141-
checked_args_cache: Optional[list[object]] = None,
142+
checked_args_cache: Optional[list[Optional[CheckedArgs]]] = None,
142143
) -> None:
143144
"""
144145
Evaluate this statement, using the output of execute_args
@@ -195,7 +196,7 @@ def call_in_context(
195196
queue: QueueScheduler,
196197
result: ResultVariable,
197198
*,
198-
checked_args_cache: Optional[list[object]] = None,
199+
checked_args_cache: Optional[list[Optional[CheckedArgs]]] = None,
199200
) -> None:
200201
"""
201202
Call this function in the supplied context and store the result in the supplied ResultVariable.
@@ -227,7 +228,7 @@ def call_in_context(
227228
queue: QueueScheduler,
228229
result: ResultVariable,
229230
*,
230-
checked_args_cache: Optional[list[object]] = None,
231+
checked_args_cache: Optional[list[Optional[CheckedArgs]]] = None,
231232
) -> None:
232233
result.set_value(self.call_direct(args, kwargs), self.ast_node.location)
233234

@@ -274,15 +275,16 @@ def call_in_context(
274275
queue: QueueScheduler,
275276
result: ResultVariable,
276277
*,
277-
checked_args_cache: Optional[list[object]] = None,
278+
checked_args_cache: Optional[list[Optional[CheckedArgs]]] = None,
278279
) -> None:
279280

280-
if checked_args_cache is not None and checked_args_cache[0] is not None:
281+
cached = checked_args_cache[0] if checked_args_cache is not None else None
282+
if cached is not None:
281283
# Reuse validated args from a previous call (reschedule after UnsetException).
282284
# Type validation and domain conversion are deterministic for the same inputs,
283285
# and the DynamicProxy wrappers remain valid since they read from the same
284286
# underlying entity instances.
285-
processed_args = checked_args_cache[0]
287+
processed_args = cached
286288
else:
287289
processed_args = self.plugin.check_args(args, kwargs)
288290
no_unknows = not processed_args.unknowns
@@ -359,7 +361,7 @@ def __init__(
359361
# Cache for validated plugin arguments, reused across reschedules to avoid
360362
# redundant type validation when a plugin is retried after UnsetException.
361363
# Single-element list used as a mutable slot that can be written to by call_in_context.
362-
self._checked_args_cache: list[object] = [None]
364+
self._checked_args_cache: list[Optional[CheckedArgs]] = [None]
363365

364366
def execute(self) -> None:
365367
# Execution in two stages to prevent re-execution of argument expressions

0 commit comments

Comments
 (0)