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

Method to_python_class

py/generate_bidi.py:546–565  ·  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

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