Skip to content

PythonCode

Base classes

Name Children Inherits
BaseCode
schemez.code
Base class for syntax-validated code.

⋔ Inheritance diagram

graph TD
  2056826303["code.PythonCode"]
  2935550820["code.BaseCode"]
  330168112["schema.Schema"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  2935550820 --> 2056826303
  330168112 --> 2935550820
  3879467795 --> 330168112
  2751680898 --> 3879467795

🛈 DocStrings

Bases: BaseCode

Python with syntax validation.

Source code in src/schemez/code.py
class PythonCode(BaseCode):
    """Python with syntax validation."""

    @field_validator("code")
    @classmethod
    def validate_syntax(cls, code: str) -> str:
        try:
            ast.parse(code)
        except SyntaxError as e:
            msg = f"Invalid Python syntax: {e}"
            raise ValueError(msg) from e
        else:
            return code

:fa-brands-github: Show source on GitHub