44
55import dataclasses
66import inspect
7- import sys
87import types
98import urllib .parse
109from base64 import b64encode
@@ -541,7 +540,7 @@ class JavasciptKeyboardEvent:
541540 shiftKey : bool = False # noqa: N815
542541
543542
544- def input_event (e : Var [JavascriptInputEvent ]) -> Tuple [Var [str ]]:
543+ def input_event (e : ObjectVar [JavascriptInputEvent ]) -> Tuple [Var [str ]]:
545544 """Get the value from an input event.
546545
547546 Args:
@@ -562,7 +561,9 @@ class KeyInputInfo(TypedDict):
562561 shift_key : bool
563562
564563
565- def key_event (e : Var [JavasciptKeyboardEvent ]) -> Tuple [Var [str ], Var [KeyInputInfo ]]:
564+ def key_event (
565+ e : ObjectVar [JavasciptKeyboardEvent ],
566+ ) -> Tuple [Var [str ], Var [KeyInputInfo ]]:
566567 """Get the key from a keyboard event.
567568
568569 Args:
@@ -572,15 +573,15 @@ def key_event(e: Var[JavasciptKeyboardEvent]) -> Tuple[Var[str], Var[KeyInputInf
572573 The key from the keyboard event.
573574 """
574575 return (
575- e .key ,
576+ e .key . to ( str ) ,
576577 Var .create (
577578 {
578579 "alt_key" : e .altKey ,
579580 "ctrl_key" : e .ctrlKey ,
580581 "meta_key" : e .metaKey ,
581582 "shift_key" : e .shiftKey ,
582583 },
583- ),
584+ ). to ( KeyInputInfo ) ,
584585 )
585586
586587
@@ -1354,7 +1355,7 @@ def unwrap_var_annotation(annotation: GenericType):
13541355 Returns:
13551356 The unwrapped annotation.
13561357 """
1357- if get_origin (annotation ) is Var and (args := get_args (annotation )):
1358+ if get_origin (annotation ) in ( Var , ObjectVar ) and (args := get_args (annotation )):
13581359 return args [0 ]
13591360 return annotation
13601361
@@ -1620,7 +1621,7 @@ class EventVar(ObjectVar, python_types=EventSpec):
16201621@dataclasses .dataclass (
16211622 eq = False ,
16221623 frozen = True ,
1623- ** { " slots" : True } if sys . version_info >= ( 3 , 10 ) else {} ,
1624+ slots = True ,
16241625)
16251626class LiteralEventVar (VarOperationCall , LiteralVar , EventVar ):
16261627 """A literal event var."""
@@ -1681,7 +1682,7 @@ class EventChainVar(BuilderFunctionVar, python_types=EventChain):
16811682@dataclasses .dataclass (
16821683 eq = False ,
16831684 frozen = True ,
1684- ** { " slots" : True } if sys . version_info >= ( 3 , 10 ) else {} ,
1685+ slots = True ,
16851686)
16861687# Note: LiteralVar is second in the inheritance list allowing it act like a
16871688# CachedVarOperation (ArgsFunctionOperation) and get the _js_expr from the
@@ -1713,6 +1714,9 @@ def create(
17131714
17141715 Returns:
17151716 The created LiteralEventChainVar instance.
1717+
1718+ Raises:
1719+ ValueError: If the invocation is not a FunctionVar.
17161720 """
17171721 arg_spec = (
17181722 value .args_spec [0 ]
@@ -1740,6 +1744,11 @@ def create(
17401744 else :
17411745 invocation = value .invocation
17421746
1747+ if invocation is not None and not isinstance (invocation , FunctionVar ):
1748+ raise ValueError (
1749+ f"EventChain invocation must be a FunctionVar, got { invocation !s} of type { invocation ._var_type !s} ."
1750+ )
1751+
17431752 return cls (
17441753 _js_expr = "" ,
17451754 _var_type = EventChain ,
0 commit comments