From f194efecaec09a58d50faceb9bf33fd1042fa7c9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 12 Apr 2026 18:08:16 -0400 Subject: [PATCH] Replace assert with proper exceptions in OpenAPI extension assert statements are stripped with python -O. Use ValueError for duplicate schema registration and RuntimeError for missing static route configuration. Co-Authored-By: Claude Opus 4.6 (1M context) --- responder/ext/openapi/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/responder/ext/openapi/__init__.py b/responder/ext/openapi/__init__.py index 7121af7..bb70905 100644 --- a/responder/ext/openapi/__init__.py +++ b/responder/ext/openapi/__init__.py @@ -174,8 +174,8 @@ class OpenAPISchema: def add_schema(self, name, schema, check_existing=True): """Adds a marshmallow or Pydantic schema to the API specification.""" if check_existing: - assert name not in self.schemas - assert name not in self.pydantic_schemas + if name in self.schemas or name in self.pydantic_schemas: + raise ValueError(f"Schema '{name}' is already registered") if _is_pydantic_model(schema): self.pydantic_schemas[name] = schema @@ -221,7 +221,8 @@ class OpenAPISchema: def static_url(self, asset): """Given a static asset, return its URL path.""" - assert self.static_route is not None + if self.static_route is None: + raise RuntimeError("Cannot generate static URL: static_route is disabled") return f"{self.static_route}/{str(asset)}" def docs_response(self, req, resp):