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

Convert Values Retrieved from URLs #8

Open
da3dsoul opened this issue Mar 4, 2019 · 9 comments
Open

Convert Values Retrieved from URLs #8

da3dsoul opened this issue Mar 4, 2019 · 9 comments

Comments

@da3dsoul
Copy link

da3dsoul commented Mar 4, 2019

It took a bit to debug and find this.
I pass False to url_for, and it give the proper result. Then in the method that gets called, I get str('False').

if 'False':
    # this is too true for False

This doesn't need to convert fancy things, but simple int, bool, and maybe float would save a lot of annoying work sanitizing a parameter that could easily be checked for param.isnumeric() or param.lower() == 'true'.

@da3dsoul
Copy link
Author

da3dsoul commented Mar 4, 2019

I might just PR this myself, but if someone does it first, then cool.

@da3dsoul
Copy link
Author

da3dsoul commented Mar 7, 2019

#10 implements this

@dagwieers
Copy link
Contributor

I am not a big fan of this automatic conversion. It also breaks existing uses.

@da3dsoul
Copy link
Author

You need to ask it to do this. It defaults to False. I didn't do anything that would be a breaking change

@da3dsoul
Copy link
Author

plugin = routing.Plugin('some base url', convert_args=True)

@dagwieers
Copy link
Contributor

Still no fan ;-)

@da3dsoul
Copy link
Author

The argument for this is that when you use routing systems, you want it to give back what you put in. Python's type...fun...makes checking your expected types even more annoying. This simple feature saves a lot of heartache and frustration just from knowing that if you give it a number, it'll give you a number back.

@da3dsoul
Copy link
Author

da3dsoul commented Jan 11, 2020

To further discuss this, as it seems at least @dagwieers doesn't like it, I'm thinking that optional strict typing in the URL may be a solution.

Similar to how we have paths, essentially, you apply a modifier to enforce both matching a specific type and automatically converting back to the desired type. This will allow simple types, such as int, float, etc, but also models to be serialized and deserialized. I wouldn't suggest anything more complicated than

{ "Name": "Dave", "Dead":True }

but it could help with passing simple models without a lot of effort trying to convert back and forth, as mentioned in #7

@da3dsoul
Copy link
Author

da3dsoul commented Jan 11, 2020

With object persistence, theoretically it could build a small cache, then the Object is saved to the cache and referenced by a one-time ID to be retrieved on the next call. This method wouldn't work for communication with a script, which is another issue, but it could allow for much cleaner URLs while allowing more automagical persistence for devs that depend on this project. That in itself may be beyond the scope of this project, as well, though.

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

No branches or pull requests

2 participants