Generate Python dataclass code for the event info type. Returns a dataclass code that attempts to use globals().get() for safety.
(self)
| 590 | description: str = "" |
| 591 | |
| 592 | def to_python_dataclass(self) -> str: |
| 593 | """Generate Python dataclass code for the event info type. |
| 594 | |
| 595 | Returns a dataclass code that attempts to use globals().get() for safety. |
| 596 | """ |
| 597 | class_name = self.name |
| 598 | |
| 599 | # Extract the type name from params_type (e.g., "browsingContext.Info" -> "Info") |
| 600 | # The params_type comes from the CDDL and includes module prefix |
| 601 | type_name = self.params_type.split(".")[-1] if "." in self.params_type else self.params_type |
| 602 | |
| 603 | # Special case: if the type is BaseNavigationInfo, use BaseNavigationInfo directly |
| 604 | # (NavigationInfo will be created as an alias to it) |
| 605 | if type_name == "NavigationInfo": |
| 606 | type_name = "BaseNavigationInfo" |
| 607 | |
| 608 | # Generate type alias using globals().get() for safety |
| 609 | code = f"# Event: {self.method}\n" |
| 610 | code += f"{class_name} = globals().get('{type_name}', dict) # Fallback to dict if type not defined\n" |
| 611 | |
| 612 | return code |
| 613 | |
| 614 | |
| 615 | @dataclass |