LiteralEventChainVar becomes an ArgsFunctionOperation
Instead of using the ArgsFunctionOperation to create the string representation of the _js_expr, make the identity of the var an ArgsFunctionOperation so the _args_names and _return_expr remain accessible. Rely on the default behavior of ArgsFunctionOperation to create the _cached_var_name / _js_expr value. This allows the compat shim in `format_event_chain` to remain functional, as it does special handling for ArgsFunctionOperation to retain the previous behavior of that function (this was a regression introduced in 0.6.2).
This commit is contained in:
parent
d6797a1f1d
commit
3a2c76af31
@ -1332,7 +1332,7 @@ class EventChainVar(FunctionVar):
|
|||||||
frozen=True,
|
frozen=True,
|
||||||
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
||||||
)
|
)
|
||||||
class LiteralEventChainVar(CachedVarOperation, LiteralVar, EventChainVar):
|
class LiteralEventChainVar(ArgsFunctionOperation, EventChainVar, LiteralVar):
|
||||||
"""A literal event chain var."""
|
"""A literal event chain var."""
|
||||||
|
|
||||||
_var_value: EventChain = dataclasses.field(default=None) # type: ignore
|
_var_value: EventChain = dataclasses.field(default=None) # type: ignore
|
||||||
@ -1345,41 +1345,6 @@ class LiteralEventChainVar(CachedVarOperation, LiteralVar, EventChainVar):
|
|||||||
"""
|
"""
|
||||||
return hash((self.__class__.__name__, self._js_expr))
|
return hash((self.__class__.__name__, self._js_expr))
|
||||||
|
|
||||||
@cached_property_no_lock
|
|
||||||
def _cached_var_name(self) -> str:
|
|
||||||
"""The name of the var.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The name of the var.
|
|
||||||
"""
|
|
||||||
sig = inspect.signature(self._var_value.args_spec) # type: ignore
|
|
||||||
if sig.parameters:
|
|
||||||
arg_def = tuple((f"_{p}" for p in sig.parameters))
|
|
||||||
arg_def_expr = LiteralVar.create([Var(_js_expr=arg) for arg in arg_def])
|
|
||||||
else:
|
|
||||||
# add a default argument for addEvents if none were specified in value.args_spec
|
|
||||||
# used to trigger the preventDefault() on the event.
|
|
||||||
arg_def = ("...args",)
|
|
||||||
arg_def_expr = Var(_js_expr="args")
|
|
||||||
|
|
||||||
if self._var_value.invocation is None:
|
|
||||||
invocation = FunctionStringVar.create("addEvents")
|
|
||||||
else:
|
|
||||||
invocation = self._var_value.invocation
|
|
||||||
|
|
||||||
return str(
|
|
||||||
ArgsFunctionOperation.create(
|
|
||||||
arg_def,
|
|
||||||
invocation.call(
|
|
||||||
LiteralVar.create(
|
|
||||||
[LiteralVar.create(event) for event in self._var_value.events]
|
|
||||||
),
|
|
||||||
arg_def_expr,
|
|
||||||
self._var_value.event_actions,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
cls,
|
cls,
|
||||||
@ -1395,10 +1360,31 @@ class LiteralEventChainVar(CachedVarOperation, LiteralVar, EventChainVar):
|
|||||||
Returns:
|
Returns:
|
||||||
The created LiteralEventChainVar instance.
|
The created LiteralEventChainVar instance.
|
||||||
"""
|
"""
|
||||||
|
sig = inspect.signature(value.args_spec) # type: ignore
|
||||||
|
if sig.parameters:
|
||||||
|
arg_def = tuple((f"_{p}" for p in sig.parameters))
|
||||||
|
arg_def_expr = LiteralVar.create([Var(_js_expr=arg) for arg in arg_def])
|
||||||
|
else:
|
||||||
|
# add a default argument for addEvents if none were specified in value.args_spec
|
||||||
|
# used to trigger the preventDefault() on the event.
|
||||||
|
arg_def = ("...args",)
|
||||||
|
arg_def_expr = Var(_js_expr="args")
|
||||||
|
|
||||||
|
if value.invocation is None:
|
||||||
|
invocation = FunctionStringVar.create("addEvents")
|
||||||
|
else:
|
||||||
|
invocation = value.invocation
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
_js_expr="",
|
_js_expr="",
|
||||||
_var_type=EventChain,
|
_var_type=Callable,
|
||||||
_var_data=_var_data,
|
_var_data=_var_data,
|
||||||
|
_args_names=arg_def,
|
||||||
|
_return_expr=invocation.call(
|
||||||
|
LiteralVar.create([LiteralVar.create(event) for event in value.events]),
|
||||||
|
arg_def_expr,
|
||||||
|
value.event_actions,
|
||||||
|
),
|
||||||
_var_value=value,
|
_var_value=value,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user