Open vytas7 opened 2 years ago
Perhaps we could support escaping curly brackets by doubling them ({{
& }}
), just as the Python format string syntax does?
Perhaps we could support escaping curly brackets by doubling them (
{{
&}}
), just as the Python format string syntax does?
I like that idea, since it would be somewhat natural to python users to escape them that way. Especially since f-string has become a thing
(It's the same {{
& }}
even in str.format()
, which dates back to early 3.x versions and 2.7.)
Double Braces {{
feel like bloating the route string/parameter definition.
Looking into where this parseing happens i think it would be best, keeping multiple parametercases in mind, to split parsing into
two steps:
{
like {object_id:int}
in the segment obj_{object_id:int}_img
This should cover at least all python native, non-recursive (not Object of Object of ...), structures.
@chgad thanks for the input, I remember our discussion at the EuroPython2024 Sprint :) Just checking you had any code prototypes left in this direction, if you wrote any back then?
At the time of this writing, it is cumbersome to instantiate converters with any parameter containing curly brackets in its expression.
For instance, the following attempt to validate color to be one of
"red"
,"green"
or"blue"
... fails with the following
ValueError: Field names must be valid identifiers (""red", "green", "blue"" is not valid)
.One could easily work around the problem in this contrived example by using a list or tuple instead of the set literal, but what if we need curly brackets in a regex, or need to pass a
dict
?