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

Method to_python_class

py/generate_bidi.py:536–555  ·  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

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