improve error message for methods argument in HTTP method decorators

Clarify the TypeError raised when passing 'methods' to HTTP method
decorators (get, post, etc.) by indicating which decorator was used
and explicitly stating to use 'route' instead.
This commit is contained in:
goingforstudying-ctrl 2026-05-21 17:17:53 +00:00
parent 954f5684e4
commit b70441f721

View file

@ -288,7 +288,10 @@ class Scaffold:
options: dict[str, t.Any],
) -> t.Callable[[T_route], T_route]:
if "methods" in options:
raise TypeError("Use the 'route' decorator to use the 'methods' argument.")
raise TypeError(
"The 'methods' argument is not allowed when using "
f"'{method.lower()}' decorator. Use the 'route' decorator instead."
)
return self.route(rule, methods=[method], **options)