Skip to content

Commit 7236ac3

Browse files
committed
Python: keep None checks for non-optional params
1 parent c057217 commit 7236ac3

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎python/semantic_kernel/functions/kernel_function_from_method.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ def gather_function_parameters(self, context: FunctionInvocationContext) -> dict
176176
continue
177177
if param.name in context.arguments:
178178
value: Any = context.arguments[param.name]
179+
accepts_none = not param.is_required and param.default_value is None
179180
if (
180-
value is not None
181+
not (value is None and accepts_none)
181182
and param.type_
182183
and "," not in param.type_
183184
and param.type_object

‎python/tests/unit/functions/test_kernel_function_from_method.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,21 @@ def func_optional(
700700
assert res.value == (3, "x", None)
701701

702702

703+
async def test_explicit_none_for_non_optional_parameters_raises(kernel: Kernel):
704+
@kernel_function
705+
def func_required(count: int) -> int:
706+
return count
707+
708+
@kernel_function
709+
def func_int_default(count: int = 5) -> int:
710+
return count
711+
712+
for method in (func_required, func_int_default):
713+
func = KernelFunction.from_method(method, "test")
714+
with pytest.raises(FunctionExecutionException, match="Parameter count is expected to be parsed"):
715+
await func.invoke(kernel=kernel, arguments=KernelArguments(count=None))
716+
717+
703718
async def test_default_handling(kernel: Kernel):
704719
@kernel_function
705720
def func_default(input: str = "test"):

0 commit comments

Comments
 (0)