-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Parse zero padded integers as strings #25
base: master
Are you sure you want to change the base?
Parse zero padded integers as strings #25
Conversation
Checks have failed due to |
ping @jpadilla |
Hey @gertjanol thanks for putting this together. I'm kind of torn and not sure what the right solution would be. This as is would be a breaking change right now. Also, it would now parse At this point I'm inclining towards perhaps making a note of the existing behavior in the docs and just leaving it to users to implement their expected type conversions. |
Myeah, you're right about this being a breaking change. I'm not sure how big of an issue that is though :). How do you envision users implementing their own type conversion? Subclass this Parser? |
@gertjanol I'd rather not make this type of assumption going on forward and instead enable users to override the parser however they see fit. I'm actually inclined on just adding/documenting the necessary public API methods, making zero assumptions the current |
Hey @jpadilla. Alright, sounds like a plan! So then the forced cast to Another solution I thought of, that might be the most simple, is adding a setting for this specific use case. Something like this
Default would be Drawback is that this might lead to other settings for every quirk that you can think of :). |
@gertjanol that's right, by default this new method will just return whatever the original value was. In the release note we would have to document what the original behavior was so people depending on it can just copy/paste a parser with that behavior. |
See #26 |
Thanks for your work in this library! We're considering using it for a project, but one of the things that we run in to is that our users have values in their XML that look (and parse) like integers, but are actually strings. These values look like
<code>000123</code>
.The parser incorrectly assumes these are integers, and in the process throws away information (the leading zeroes). The renderer works correctly though: the Python-structure
{'code': '000123'}
is rendered correctly to<code>000123</code>
. So for one, the symmetry between parser and renderer is missing here.This PR checks if values have a leading zero, and then does no processing at all. In the process I added some more tests to clarify existing behavior.