Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions custom_components/pyscript/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def get_positional_args(self):
args.append(arg.arg)
return args

async def call(self, ast_ctx, *args, **kwargs):
async def call(self, ast_ctx, /, *args, **kwargs):
"""Call the function with the given context and arguments."""
sym_table = {}
if args is None:
Expand Down Expand Up @@ -1053,7 +1053,7 @@ def get_func(self) -> EvalFunc:
"""Return the EvalFunc function."""
return self.func

async def call(self, ast_ctx, *args, **kwargs):
async def call(self, ast_ctx, /, *args, **kwargs):
"""Call the EvalFunc function."""
return await self.func.call(ast_ctx, *args, **kwargs)

Expand Down Expand Up @@ -1087,7 +1087,7 @@ def __del__(self):
if self.func:
self.func.trigger_stop()

async def __call__(self, *args, **kwargs):
async def __call__(self, /, *args, **kwargs):
"""Call the EvalFunc function using our saved ast ctx."""
return await self.func.call(self.ast_ctx, *args, **kwargs)

Expand All @@ -1105,11 +1105,11 @@ def __init__(self, func: EvalFunc, ast_ctx: "AstEval", class_inst: Any) -> None:
self.ast_ctx = ast_ctx
self.class_inst = class_inst

async def call(self, ast_ctx, *args, **kwargs):
async def call(self, ast_ctx, /, *args, **kwargs):
"""Call the EvalFunc function."""
return await self.func.call(ast_ctx, self.class_inst, *args, **kwargs)

async def __call__(self, *args, **kwargs):
async def __call__(self, /, *args, **kwargs):
"""Call the function using our saved ast ctx and class instance."""
return await self.func.call(self.ast_ctx, self.class_inst, *args, **kwargs)

Expand Down Expand Up @@ -2536,7 +2536,7 @@ def super_args(self):
first_arg = first_arg.get()
return func.class_cell[0], first_arg

async def call_func(self, func, func_name, *args, **kwargs):
async def call_func(self, func, func_name, /, *args, **kwargs):
"""Call a function with the given arguments."""
if func_name is None:
try:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_unit_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,25 @@ def method1():
""",
1234,
],
["def echo(func): return func\necho(func=42)", 42],
[
"""
class Echo:
def method(instance, **kwargs):
return kwargs

@pyscript_compile
async def invoke(callback, kwargs):
return await callback(**kwargs)

def echo(**kwargs):
return kwargs

kw = dict(func=1, func_name=2, ast_ctx=3, self=4)
[echo(**kw), Echo().method(**kw), invoke(echo, kw), invoke(Echo().method, kw)]
""",
[{"func": 1, "func_name": 2, "ast_ctx": 3, "self": 4}] * 4,
],
[
"""
def foo(x=30, *args, y = 123, **kwargs):
Expand Down
Loading