3333else :
3434 from typing_extensions import Literal , TypedDict
3535
36+ if sys .version_info >= (3 , 10 ):
37+ from typing import ParamSpec
38+ else :
39+ from typing_extensions import ParamSpec
40+
3641if sys .version_info >= (3 , 11 ):
37- from typing import NotRequired
42+ from typing import NotRequired , cast
3843else :
39- from typing_extensions import NotRequired
44+ from typing_extensions import NotRequired , cast
4045
4146from . import _frida
4247
@@ -72,15 +77,18 @@ def _filter_missing_kwargs(d: MutableMapping[Any, Any]) -> None:
7277 d .pop (key )
7378
7479
75- R = TypeVar ("R" )
80+ P = ParamSpec ("P" )
81+ R = TypeVar ("R" , covariant = True )
7682
7783
78- def cancellable (f : Callable [..., R ]) -> Callable [..., R ]:
84+ def cancellable (f : Callable [P , R ]) -> Callable [P , R ]:
85+ # currently there is no way to type properly the extended callable with optional cancellable parameter
86+ # ref: https://github.com/python/typing/discussions/1905#discussioncomment-11696995
7987 @functools .wraps (f )
80- def wrapper (* args : Any , ** kwargs : Any ) -> R :
88+ def wrapper (* args : P . args , ** kwargs : P . kwargs ) -> R :
8189 cancellable = kwargs .pop ("cancellable" , None )
8290 if cancellable is not None :
83- with cancellable :
91+ with cast ( Cancellable , cancellable ) :
8492 return f (* args , ** kwargs )
8593
8694 return f (* args , ** kwargs )
@@ -1554,6 +1562,12 @@ class CompilerDiagnostic(TypedDict):
15541562CompilerOutputCallback = Callable [[str ], None ]
15551563CompilerDiagnosticsCallback = Callable [[List [CompilerDiagnostic ]], None ]
15561564
1565+ CompilerOutputFormat = Literal ["unescaped" , "hex-bytes" , "c-string" ]
1566+ CompilerBundleFormat = Literal ["esm" , "iife" ]
1567+ CompilerTypeCheck = Literal ["full" , "none" ]
1568+ CompilerSourceMaps = Literal ["included" , "omitted" ]
1569+ CompilerCompression = Literal ["none" , "terser" ]
1570+ CompilerPlatform = Literal ["neutral" , "gum" , "browser" ]
15571571
15581572class Compiler :
15591573 def __init__ (self ) -> None :
@@ -1567,12 +1581,12 @@ def build(
15671581 self ,
15681582 entrypoint : str ,
15691583 project_root : Optional [str ] = None ,
1570- output_format : Optional [str ] = None ,
1571- bundle_format : Optional [str ] = None ,
1572- type_check : Optional [str ] = None ,
1573- source_maps : Optional [str ] = None ,
1574- compression : Optional [str ] = None ,
1575- platform : Optional [str ] = None ,
1584+ output_format : Optional [CompilerOutputFormat ] = None ,
1585+ bundle_format : Optional [CompilerBundleFormat ] = None ,
1586+ type_check : Optional [CompilerTypeCheck ] = None ,
1587+ source_maps : Optional [CompilerSourceMaps ] = None ,
1588+ compression : Optional [CompilerCompression ] = None ,
1589+ platform : Optional [CompilerPlatform ] = None ,
15761590 externals : Optional [Sequence [str ]] = None ,
15771591 ) -> str :
15781592 kwargs = {
@@ -1593,12 +1607,12 @@ def watch(
15931607 self ,
15941608 entrypoint : str ,
15951609 project_root : Optional [str ] = None ,
1596- output_format : Optional [str ] = None ,
1597- bundle_format : Optional [str ] = None ,
1598- type_check : Optional [str ] = None ,
1599- source_maps : Optional [str ] = None ,
1600- compression : Optional [str ] = None ,
1601- platform : Optional [str ] = None ,
1610+ output_format : Optional [CompilerOutputFormat ] = None ,
1611+ bundle_format : Optional [CompilerBundleFormat ] = None ,
1612+ type_check : Optional [CompilerTypeCheck ] = None ,
1613+ source_maps : Optional [CompilerSourceMaps ] = None ,
1614+ compression : Optional [CompilerCompression ] = None ,
1615+ platform : Optional [CompilerPlatform ] = None ,
16021616 externals : Optional [Sequence [str ]] = None ,
16031617 ) -> None :
16041618 kwargs = {
0 commit comments