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

add_route does not allow **kwargs #2038

Closed
psuresh39 opened this issue Jun 30, 2017 · 10 comments
Closed

add_route does not allow **kwargs #2038

psuresh39 opened this issue Jun 30, 2017 · 10 comments
Labels

Comments

@psuresh39
Copy link

Long story short

add_route does not allow **kwargs, it should. Open to suggestions here.

Expected behaviour

add_get supports it but not add_route. add_route should ideally support it.

Actual behaviour

Steps to reproduce

pass **kwargs to add_get will give this exception: TypeError: add_route() got an unexpected keyword argument

@asvetlov
Copy link
Member

add_route is not supposed to silently eat all unprocessed arguments.
But maybe I misunderstand your problem.
What exact argument is not supported?

@psuresh39
Copy link
Author

psuresh39 commented Jun 30, 2017

I realized I did not provide a clearer example. Here's how to repro:

def testing(request, options):
    print(options)

app = web.Application()
app.router.add_get(
    '/test',
    testing,
    option1=abc, 
    option2=xyz
)

This seems to raise a error:
TypeError: add_route() got an unexpected keyword argument

How can I pass such options into a handler ?

@asvetlov
Copy link
Member

asvetlov commented Jun 30, 2017

I don't think it's good idea.
Use app.router.add_get('/ws', functools.partial(websocket_handler, option1=abc, option2=xyz))

@psuresh39
Copy link
Author

I see what you are saying. but wouldn't it be a cleaner api for developers if they did not have to use functools and if the library behaved like other web frameworks ?

@psuresh39
Copy link
Author

I don't this it's good idea.

Did you mean you think the suggestion is a bad idea ?

@samuelcolvin
Copy link
Member

You shouldn't need to pass extra arguments to view functions. You should use app like a dictionary and add your options to the app when initialising your server.

@asvetlov
Copy link
Member

Mixing parameters for router (like add_head=True or expect_handler) with ones should be passed inside web handler makes a mess.
Why functools.partial doesn't satisfy your needs?
What other framework supports requested functionality?
IIRC neither Django not Flask.

@psuresh39
Copy link
Author

psuresh39 commented Jun 30, 2017

I see you point guys. Adding it to the app as @samuelcolvin suggested is a satisfactory approach. Thanks everyone.

@asvetlov
Copy link
Member

@samuelcolvin you caught @coolnay309 mind better than me.
I though he want to pass some per-view configuration parameter.

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants