r1chardj0n3s / parse

Parse strings using a specification based on the Python format() syntax.
http://pypi.python.org/pypi/parse
MIT License
1.72k stars 101 forks source link

explicit string format as {name_:s} does not work #116

Open martinResearch opened 4 years ago

martinResearch commented 4 years ago

Hi,

It seems that when specifying the format as :s in the formating string then parse does not work:

form = "test_{name:s}"
s = form.format(name="hello")# getting 'test_hello'
parse.parse(form , s) # getting None

Should we add a section elif type == 's': in _handle_field ?

r1chardj0n3s commented 4 years ago

Oof. Unfortunately, parse deviates from format for that one letter, s. In parse it means "whitespace". In format, when used, it means "the default string format".

I actually mis-read the format spec when writing parse and missed the mention of s :(

martinResearch commented 4 years ago

Ok. Maybe this behaviour could be controlled trough an new optional argument with default value set up to keep default behaviour unchanged to avoid breaking code that relies on it ?

r1chardj0n3s commented 4 years ago

I don't really like that as an option, as it will be very confusing. I think to fix it I'd need to make it a new major release which is backwards-incompatible in this one way.

martinResearch commented 4 years ago

I see. Is that something you would want to do ?

r1chardj0n3s commented 3 years ago

Not really, but I think I'm going to have to ;-)