77import logging
88from contextlib import asynccontextmanager
99from dataclasses import dataclass
10- from typing import AsyncIterator , Dict , Mapping , Optional , Sequence , Type , Union
10+ from typing import AsyncIterator , Dict , Mapping , Optional , Sequence , Type , Union , cast
1111
1212from typing_extensions import TypedDict
1313
1818import temporalio .converter
1919import temporalio .runtime
2020import temporalio .workflow
21-
21+ from temporalio . client import ClientConfig
2222
2323from ..common import HeaderCodecBehavior
2424from ._interceptor import Interceptor
25- from ._worker import load_default_build_id , WorkerConfig
26- from temporalio .client import ClientConfig
25+ from ._worker import WorkerConfig , load_default_build_id
2726from ._workflow import _WorkflowWorker
2827from ._workflow_instance import UnsandboxedWorkflowRunner , WorkflowRunner
2928from .workflow_sandbox import SandboxedWorkflowRunner
@@ -44,7 +43,9 @@ def __init__(
4443 namespace : str = "ReplayNamespace" ,
4544 data_converter : temporalio .converter .DataConverter = temporalio .converter .DataConverter .default ,
4645 interceptors : Sequence [Interceptor ] = [],
47- plugins : Sequence [Union [temporalio .worker .Plugin , temporalio .client .Plugin ]] = [],
46+ plugins : Sequence [
47+ Union [temporalio .worker .Plugin , temporalio .client .Plugin ]
48+ ] = [],
4849 build_id : Optional [str ] = None ,
4950 identity : Optional [str ] = None ,
5051 workflow_failure_exception_types : Sequence [Type [BaseException ]] = [],
@@ -86,21 +87,59 @@ def __init__(
8687
8788 # Allow plugins to configure shared configurations with worker
8889 root_worker_plugin : temporalio .worker .Plugin = temporalio .worker ._worker ._RootPlugin ()
89- for plugin in reversed ([plugin for plugin in plugins if isinstance (plugin , temporalio .worker .Plugin )]):
90+ for plugin in reversed (
91+ [
92+ plugin
93+ for plugin in plugins
94+ if isinstance (plugin , temporalio .worker .Plugin )
95+ ]
96+ ):
9097 root_worker_plugin = plugin .init_worker_plugin (root_worker_plugin )
9198
92- worker_config = WorkerConfig (** {k : v for k , v in self ._config .items () if k in WorkerConfig .__annotations__ })
99+ worker_config = cast (
100+ WorkerConfig ,
101+ {
102+ k : v
103+ for k , v in self ._config .items ()
104+ if k in WorkerConfig .__annotations__
105+ },
106+ )
107+
93108 worker_config = root_worker_plugin .configure_worker (worker_config )
94- self ._config .update ({k : v for k , v in worker_config .items () if k in ReplayerConfig .__annotations__ })
109+ self ._config .update (
110+ cast (ReplayerConfig , {
111+ k : v
112+ for k , v in worker_config .items ()
113+ if k in ReplayerConfig .__annotations__
114+ })
115+ )
95116
96117 # Allow plugins to configure shared configurations with client
97118 root_client_plugin : temporalio .client .Plugin = temporalio .client ._RootPlugin ()
98- for plugin in reversed ([plugin for plugin in plugins if isinstance (plugin , temporalio .client .Plugin )]):
99- root_client_plugin = plugin .init_client_plugin (root_client_plugin )
100-
101- client_config = ClientConfig (** {k : v for k , v in self ._config .items () if k in ClientConfig .__annotations__ })
119+ for client_plugin in reversed (
120+ [
121+ plugin
122+ for plugin in plugins
123+ if isinstance (plugin , temporalio .client .Plugin )
124+ ]
125+ ):
126+ root_client_plugin = client_plugin .init_client_plugin (root_client_plugin )
127+
128+ client_config = cast (ClientConfig ,
129+ {
130+ k : v
131+ for k , v in self ._config .items ()
132+ if k in ClientConfig .__annotations__
133+ }
134+ )
102135 client_config = root_client_plugin .configure_client (client_config )
103- self ._config .update ({k : v for k , v in client_config .items () if k in ReplayerConfig .__annotations__ })
136+ self ._config .update (
137+ cast (ReplayerConfig , {
138+ k : v
139+ for k , v in client_config .items ()
140+ if k in ReplayerConfig .__annotations__
141+ })
142+ )
104143
105144 if not self ._config ["workflows" ]:
106145 raise ValueError ("At least one workflow must be specified" )
0 commit comments