|
10 | 10 | from pathlib import Path |
11 | 11 | from typing import Any, Dict, Literal, Mapping, Optional, Union, cast |
12 | 12 |
|
13 | | -from typing_extensions import TypeAlias, TypedDict |
| 13 | +from typing_extensions import Self, TypeAlias, TypedDict |
14 | 14 |
|
15 | 15 | import temporalio.service |
16 | 16 | from temporalio.bridge.temporal_sdk_bridge import envconfig as _bridge_envconfig |
@@ -148,12 +148,12 @@ def to_connect_tls_config(self) -> Union[bool, temporalio.service.TLSConfig]: |
148 | 148 | client_private_key=_read_source(self.client_private_key), |
149 | 149 | ) |
150 | 150 |
|
151 | | - @staticmethod |
152 | | - def from_dict(d: Optional[ClientConfigTLSDict]) -> Optional[ClientConfigTLS]: |
| 151 | + @classmethod |
| 152 | + def from_dict(cls, d: Optional[ClientConfigTLSDict]) -> Optional[Self]: |
153 | 153 | """Create a ClientConfigTLS from a dictionary.""" |
154 | 154 | if not d: |
155 | 155 | return None |
156 | | - return ClientConfigTLS( |
| 156 | + return cls( |
157 | 157 | disabled=d.get("disabled"), |
158 | 158 | server_name=d.get("server_name"), |
159 | 159 | # Note: Bridge uses snake_case, but TOML uses kebab-case which is |
@@ -202,10 +202,10 @@ class ClientConfigProfile: |
202 | 202 | grpc_meta: Mapping[str, str] = field(default_factory=dict) |
203 | 203 | """gRPC metadata.""" |
204 | 204 |
|
205 | | - @staticmethod |
206 | | - def from_dict(d: ClientConfigProfileDict) -> ClientConfigProfile: |
| 205 | + @classmethod |
| 206 | + def from_dict(cls, d: ClientConfigProfileDict) -> Self: |
207 | 207 | """Create a ClientConfigProfile from a dictionary.""" |
208 | | - return ClientConfigProfile( |
| 208 | + return cls( |
209 | 209 | address=d.get("address"), |
210 | 210 | namespace=d.get("namespace"), |
211 | 211 | api_key=d.get("api_key"), |
@@ -318,14 +318,15 @@ def to_dict(self) -> Mapping[str, ClientConfigProfileDict]: |
318 | 318 | """Convert to a dictionary that can be used for TOML serialization.""" |
319 | 319 | return {k: v.to_dict() for k, v in self.profiles.items()} |
320 | 320 |
|
321 | | - @staticmethod |
| 321 | + @classmethod |
322 | 322 | def from_dict( |
| 323 | + cls, |
323 | 324 | d: Mapping[str, Mapping[str, Any]], |
324 | | - ) -> ClientConfig: |
| 325 | + ) -> Self: |
325 | 326 | """Create a ClientConfig from a dictionary.""" |
326 | 327 | # We must cast the inner dictionary because the source is often a plain |
327 | 328 | # Mapping[str, Any] from the bridge or other sources. |
328 | | - return ClientConfig( |
| 329 | + return cls( |
329 | 330 | profiles={ |
330 | 331 | k: ClientConfigProfile.from_dict(cast(ClientConfigProfileDict, v)) |
331 | 332 | for k, v in d.items() |
|
0 commit comments