-
Notifications
You must be signed in to change notification settings - Fork 12
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
Comments
I might just PR this myself, but if someone does it first, then cool. |
#10 implements this |
I am not a big fan of this automatic conversion. It also breaks existing uses. |
You need to ask it to do this. It defaults to False. I didn't do anything that would be a breaking change |
|
Still no fan ;-) |
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. |
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
but it could help with passing simple models without a lot of effort trying to convert back and forth, as mentioned in #7 |
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. |
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').
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()
orparam.lower() == 'true'
.The text was updated successfully, but these errors were encountered: