Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking responders signatures #2407

Open
jkmnt opened this issue Nov 12, 2024 · 2 comments
Open

Checking responders signatures #2407

jkmnt opened this issue Nov 12, 2024 · 2 comments

Comments

@jkmnt
Copy link

jkmnt commented Nov 12, 2024

I propose adding check if responder arguments match the template fields. Now it's easy to introduce error by renaming
arguments while refactoring.

Since this feature is likely to use the heavy inspect module, it may be implemented in inspect_app, which
imports it anyway. Then inspect_app will additionally emit warnings if arguments mismatch.
Also for type-annotated arguments it may be useful to check if type matches the field converter type.

fields = get_route_fields()
responder = get_route_responder()

req, resp, *args  = inspect.signature(responder).values()

for field, arg in zip(fields, args):
    check_arg(field, arg)
    check_anno(field, arg.annotation)
@CaselIT
Copy link
Member

CaselIT commented Nov 12, 2024

Hi,

I think this feature makes sense.
I think it may be done while adding the routes by the router (or the app), since that's is an "offline" phase where it's likely fine to execute a few more operations to check that everything works correctly.

This could probably be a configuration in the router config (or the app config?) where we have something like off | warn | error (maybe log too??). The default would likely be warn

@CaselIT CaselIT added this to the Version 4.x milestone Nov 12, 2024
@vytas7
Copy link
Member

vytas7 commented Nov 12, 2024

For the annotations part, see also #2408 that I've just filed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants