MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / to_python_class

Method to_python_class

py/generate_bidi.py:542–561  ·  view source on GitHub ↗

Generate Python enum class code. Generates a simple class with string constants to match the existing pattern in the codebase (e.g., ClientWindowState).

(self, enhancements: dict[str, Any] | None = None)

Source from the content-addressed store, hash-verified

540 description: str = ""
541
542 def to_python_class(self, enhancements: dict[str, Any] | None = None) -> str:
543 """Generate Python enum class code.
544
545 Generates a simple class with string constants to match the existing
546 pattern in the codebase (e.g., ClientWindowState).
547 """
548 enhancements = enhancements or {}
549 class_name = self.name
550 class_docstrings = enhancements.get("class_docstrings", {})
551 class_doc = _docstring_text(class_docstrings.get(class_name), class_name, self.description)
552 code = f"class {class_name}:\n"
553 code += _emit_docstring(class_doc, 4)
554 code += "\n"
555
556 for value in self.values:
557 # Convert value to UPPER_SNAKE_CASE constant name
558 const_name = self._value_to_const_name(value)
559 code += f' {const_name} = "{value}"\n'
560
561 return code
562
563 @staticmethod
564 def _value_to_const_name(value: str) -> str:

Callers 1

generate_codeMethod · 0.80

Calls 4

_value_to_const_nameMethod · 0.95
_docstring_textFunction · 0.85
_emit_docstringFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected