Deserialize event params into the wrapped Python dataclass. Args: params: Raw BiDi event params with camelCase keys. Returns: An instance of the dataclass, or the raw dict on failure.
(self, params: dict)
| 50 | self._python_class = event_class # Keep reference to Python dataclass for deserialization |
| 51 | |
| 52 | def from_json(self, params: dict) -> Any: |
| 53 | """Deserialize event params into the wrapped Python dataclass. |
| 54 | |
| 55 | Args: |
| 56 | params: Raw BiDi event params with camelCase keys. |
| 57 | |
| 58 | Returns: |
| 59 | An instance of the dataclass, or the raw dict on failure. |
| 60 | """ |
| 61 | if self._python_class is None or self._python_class is dict: |
| 62 | return params |
| 63 | try: |
| 64 | # Delegate to a classmethod from_json if the class defines one |
| 65 | if hasattr(self._python_class, "from_json") and callable(self._python_class.from_json): |
| 66 | return self._python_class.from_json(params) |
| 67 | import dataclasses as dc |
| 68 | |
| 69 | snake_params = {self._camel_to_snake(k): v for k, v in params.items()} |
| 70 | if dc.is_dataclass(self._python_class): |
| 71 | valid_fields = {f.name for f in dc.fields(self._python_class)} |
| 72 | filtered = {k: v for k, v in snake_params.items() if k in valid_fields} |
| 73 | return self._python_class(**filtered) |
| 74 | return self._python_class(**snake_params) |
| 75 | except Exception: |
| 76 | return params |
| 77 | |
| 78 | @staticmethod |
| 79 | def _camel_to_snake(name: str) -> str: |
nothing calls this directly
no test coverage detected