- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: v0.7.4
+ rev: v0.9.4
hooks:
- id: ruff
args:
def get_parameterless_sub_dependant(*, depends: params.Depends, path: str) -> Dependant:
- assert callable(
- depends.dependency
- ), "A parameter-less dependency must have a callable dependency"
+ assert callable(depends.dependency), (
+ "A parameter-less dependency must have a callable dependency"
+ )
return get_sub_dependant(depends=depends, dependency=depends.dependency, path=path)
type_annotation=param_details.type_annotation,
dependant=dependant,
):
- assert (
- param_details.field is None
- ), f"Cannot specify multiple FastAPI annotations for {param_name!r}"
+ assert param_details.field is None, (
+ f"Cannot specify multiple FastAPI annotations for {param_name!r}"
+ )
continue
assert param_details.field is not None
if isinstance(param_details.field.field_info, params.Body):
),
):
assert depends is None, f"Cannot specify `Depends` for type {type_annotation!r}"
- assert (
- field_info is None
- ), f"Cannot specify FastAPI annotation for type {type_annotation!r}"
+ assert field_info is None, (
+ f"Cannot specify FastAPI annotation for type {type_annotation!r}"
+ )
# Handle default assignations, neither field_info nor depends was not found in Annotated nor default value
elif field_info is None and depends is None:
default_value = value if value is not inspect.Signature.empty else RequiredParam
field_info=field_info,
)
if is_path_param:
- assert is_scalar_field(
- field=field
- ), "Path params must be of one of the supported types"
+ assert is_scalar_field(field=field), (
+ "Path params must be of one of the supported types"
+ )
elif isinstance(field_info, params.Query):
assert (
is_scalar_field(field)
elif field_info_in == params.ParamTypes.header:
dependant.header_params.append(field)
else:
- assert (
- field_info_in == params.ParamTypes.cookie
- ), f"non-body parameters must be in path, query, header or cookie: {field.name}"
+ assert field_info_in == params.ParamTypes.cookie, (
+ f"non-body parameters must be in path, query, header or cookie: {field.name}"
+ )
dependant.cookie_params.append(field)
if single_not_embedded_field:
field_info = first_field.field_info
- assert isinstance(
- field_info, params.Param
- ), "Params must be subclasses of Param"
+ assert isinstance(field_info, params.Param), (
+ "Params must be subclasses of Param"
+ )
loc: Tuple[str, ...] = (field_info.in_.value,)
v_, errors_ = _validate_value_with_model_field(
field=first_field, value=params_to_process, values=values, loc=loc
for field in fields:
value = _get_multidict_value(field, received_params)
field_info = field.field_info
- assert isinstance(
- field_info, params.Param
- ), "Params must be subclasses of Param"
+ assert isinstance(field_info, params.Param), (
+ "Params must be subclasses of Param"
+ )
loc = (field_info.in_.value, field.alias)
v_, errors_ = _validate_value_with_model_field(
field=field, value=value, values=values, loc=loc
openapi_response = operation_responses.setdefault(
status_code_key, {}
)
- assert isinstance(
- process_response, dict
- ), "An additional response must be a dict"
+ assert isinstance(process_response, dict), (
+ "An additional response must be a dict"
+ )
field = route.response_fields.get(additional_status_code)
additional_field_schema: Optional[Dict[str, Any]] = None
if field:
route, routing.APIRoute
):
if route.body_field:
- assert isinstance(
- route.body_field, ModelField
- ), "A request body must be a Pydantic Field"
+ assert isinstance(route.body_field, ModelField), (
+ "A request body must be a Pydantic Field"
+ )
body_fields_from_routes.append(route.body_field)
if route.response_field:
responses_from_routes.append(route.response_field)
status_code = int(status_code)
self.status_code = status_code
if self.response_model:
- assert is_body_allowed_for_status_code(
- status_code
- ), f"Status code {status_code} must not have a response body"
+ assert is_body_allowed_for_status_code(status_code), (
+ f"Status code {status_code} must not have a response body"
+ )
response_name = "Response_" + self.unique_id
self.response_field = create_model_field(
name=response_name,
assert isinstance(response, dict), "An additional response must be a dict"
model = response.get("model")
if model:
- assert is_body_allowed_for_status_code(
- additional_status_code
- ), f"Status code {additional_status_code} must not have a response body"
+ assert is_body_allowed_for_status_code(additional_status_code), (
+ f"Status code {additional_status_code} must not have a response body"
+ )
response_name = f"Response_{additional_status_code}_{self.unique_id}"
response_field = create_model_field(
name=response_name, type_=model, mode="serialization"
)
if prefix:
assert prefix.startswith("/"), "A path prefix must start with '/'"
- assert not prefix.endswith(
- "/"
- ), "A path prefix must not end with '/', as the routes will start with '/'"
+ assert not prefix.endswith("/"), (
+ "A path prefix must not end with '/', as the routes will start with '/'"
+ )
self.prefix = prefix
self.tags: List[Union[str, Enum]] = tags or []
self.dependencies = list(dependencies or [])
"""
if prefix:
assert prefix.startswith("/"), "A path prefix must start with '/'"
- assert not prefix.endswith(
- "/"
- ), "A path prefix must not end with '/', as the routes will start with '/'"
+ assert not prefix.endswith("/"), (
+ "A path prefix must not end with '/', as the routes will start with '/'"
+ )
else:
for r in router.routes:
path = getattr(r, "path") # noqa: B009
# For mkdocstrings and tests
httpx >=0.23.0,<0.28.0
# For linting and generating docs versions
-ruff ==0.6.4
+ruff ==0.9.4
def generate_lang_path(*, lang: str, path: Path) -> Path:
en_docs_path = Path("docs/en/docs")
- assert str(path).startswith(
- str(en_docs_path)
- ), f"Path must be inside {en_docs_path}"
+ assert str(path).startswith(str(en_docs_path)), (
+ f"Path must be inside {en_docs_path}"
+ )
lang_docs_path = Path(f"docs/{lang}/docs")
out_path = Path(str(path).replace(str(en_docs_path), str(lang_docs_path)))
return out_path
lang_prompt_content = lang_prompt_path.read_text()
en_docs_path = Path("docs/en/docs")
- assert str(path).startswith(
- str(en_docs_path)
- ), f"Path must be inside {en_docs_path}"
+ assert str(path).startswith(str(en_docs_path)), (
+ f"Path must be inside {en_docs_path}"
+ )
out_path = generate_lang_path(lang=lang, path=path)
out_path.parent.mkdir(parents=True, exist_ok=True)
original_content = path.read_text()
"type": "array",
},
"msg": {"title": "Message", "type": "string"},
- "type": {"title": "Error " "Type", "type": "string"},
+ "type": {"title": "Error Type", "type": "string"},
},
"required": ["loc", "msg", "type"],
"title": "ValidationError",
"responses": {
"200": {
"content": {"application/json": {"schema": {}}},
- "description": "Successful " "Response",
+ "description": "Successful Response",
},
"422": {
"content": {
}
}
},
- "description": "Validation " "Error",
+ "description": "Validation Error",
},
},
"summary": "Foo Handler",
"responses": {
"200": {
"content": {"application/json": {"schema": {}}},
- "description": "Successful " "Response",
+ "description": "Successful Response",
}
},
"summary": "A",
"responses": {
"200": {
"content": {"application/json": {"schema": {}}},
- "description": "Successful " "Response",
+ "description": "Successful Response",
}
},
"summary": "B",
"type": "array",
},
"msg": {"title": "Message", "type": "string"},
- "type": {"title": "Error " "Type", "type": "string"},
+ "type": {"title": "Error Type", "type": "string"},
},
"required": ["loc", "msg", "type"],
"title": "ValidationError",
"responses": {
"200": {
"content": {"application/json": {"schema": {}}},
- "description": "Successful " "Response",
+ "description": "Successful Response",
},
"422": {
"content": {
}
}
},
- "description": "Validation " "Error",
+ "description": "Validation Error",
},
},
"summary": "Get Deps",
def test_swagger_ui():
response = client.get("/docs")
assert response.status_code == 200, response.text
- assert (
- '"syntaxHighlight": false' in response.text
- ), "syntaxHighlight should be included and converted to JSON"
- assert (
- '"dom_id": "#swagger-ui"' in response.text
- ), "default configs should be preserved"
+ assert '"syntaxHighlight": false' in response.text, (
+ "syntaxHighlight should be included and converted to JSON"
+ )
+ assert '"dom_id": "#swagger-ui"' in response.text, (
+ "default configs should be preserved"
+ )
assert "presets: [" in response.text, "default configs should be preserved"
- assert (
- "SwaggerUIBundle.presets.apis," in response.text
- ), "default configs should be preserved"
- assert (
- "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text
- ), "default configs should be preserved"
- assert (
- '"layout": "BaseLayout",' in response.text
- ), "default configs should be preserved"
- assert (
- '"deepLinking": true,' in response.text
- ), "default configs should be preserved"
- assert (
- '"showExtensions": true,' in response.text
- ), "default configs should be preserved"
- assert (
- '"showCommonExtensions": true,' in response.text
- ), "default configs should be preserved"
+ assert "SwaggerUIBundle.presets.apis," in response.text, (
+ "default configs should be preserved"
+ )
+ assert "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"layout": "BaseLayout",' in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"deepLinking": true,' in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"showExtensions": true,' in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"showCommonExtensions": true,' in response.text, (
+ "default configs should be preserved"
+ )
def test_get_users():
def test_swagger_ui():
response = client.get("/docs")
assert response.status_code == 200, response.text
- assert (
- '"syntaxHighlight": false' not in response.text
- ), "not used parameters should not be included"
- assert (
- '"syntaxHighlight": {"theme": "obsidian"}' in response.text
- ), "parameters with middle dots should be included in a JSON compatible way"
- assert (
- '"dom_id": "#swagger-ui"' in response.text
- ), "default configs should be preserved"
+ assert '"syntaxHighlight": false' not in response.text, (
+ "not used parameters should not be included"
+ )
+ assert '"syntaxHighlight": {"theme": "obsidian"}' in response.text, (
+ "parameters with middle dots should be included in a JSON compatible way"
+ )
+ assert '"dom_id": "#swagger-ui"' in response.text, (
+ "default configs should be preserved"
+ )
assert "presets: [" in response.text, "default configs should be preserved"
- assert (
- "SwaggerUIBundle.presets.apis," in response.text
- ), "default configs should be preserved"
- assert (
- "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text
- ), "default configs should be preserved"
- assert (
- '"layout": "BaseLayout",' in response.text
- ), "default configs should be preserved"
- assert (
- '"deepLinking": true,' in response.text
- ), "default configs should be preserved"
- assert (
- '"showExtensions": true,' in response.text
- ), "default configs should be preserved"
- assert (
- '"showCommonExtensions": true,' in response.text
- ), "default configs should be preserved"
+ assert "SwaggerUIBundle.presets.apis," in response.text, (
+ "default configs should be preserved"
+ )
+ assert "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"layout": "BaseLayout",' in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"deepLinking": true,' in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"showExtensions": true,' in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"showCommonExtensions": true,' in response.text, (
+ "default configs should be preserved"
+ )
def test_get_users():
def test_swagger_ui():
response = client.get("/docs")
assert response.status_code == 200, response.text
- assert (
- '"deepLinking": false,' in response.text
- ), "overridden configs should be preserved"
- assert (
- '"deepLinking": true' not in response.text
- ), "overridden configs should not include the old value"
- assert (
- '"syntaxHighlight": false' not in response.text
- ), "not used parameters should not be included"
- assert (
- '"dom_id": "#swagger-ui"' in response.text
- ), "default configs should be preserved"
+ assert '"deepLinking": false,' in response.text, (
+ "overridden configs should be preserved"
+ )
+ assert '"deepLinking": true' not in response.text, (
+ "overridden configs should not include the old value"
+ )
+ assert '"syntaxHighlight": false' not in response.text, (
+ "not used parameters should not be included"
+ )
+ assert '"dom_id": "#swagger-ui"' in response.text, (
+ "default configs should be preserved"
+ )
assert "presets: [" in response.text, "default configs should be preserved"
- assert (
- "SwaggerUIBundle.presets.apis," in response.text
- ), "default configs should be preserved"
- assert (
- "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text
- ), "default configs should be preserved"
- assert (
- '"layout": "BaseLayout",' in response.text
- ), "default configs should be preserved"
- assert (
- '"showExtensions": true,' in response.text
- ), "default configs should be preserved"
- assert (
- '"showCommonExtensions": true,' in response.text
- ), "default configs should be preserved"
+ assert "SwaggerUIBundle.presets.apis," in response.text, (
+ "default configs should be preserved"
+ )
+ assert "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"layout": "BaseLayout",' in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"showExtensions": true,' in response.text, (
+ "default configs should be preserved"
+ )
+ assert '"showCommonExtensions": true,' in response.text, (
+ "default configs should be preserved"
+ )
def test_get_users():
assert response.json() == snapshot(
{"age": 30, "id": IsInt(), "name": "Dead Pond"}
)
- assert (
- response.json()["id"] != 9000
- ), "The ID should be generated by the database"
+ assert response.json()["id"] != 9000, (
+ "The ID should be generated by the database"
+ )
# Read a hero
hero_id = response.json()["id"]