Repository navigation
Write FLOAT values without an exponent - #2137
Conversation
vFloat.to_ical() and vGeo.to_ical() wrote very small and very large numbers as 1e-05, which RFC 5545 section 3.3.7 does not allow. Closes PyCalendar#2136
|
Thanks for the pull request, @fermsp! A maintainer will review it shortly. |
Insufficient dataNot enough activity yet to make a reliable assessment. This is an automated analysis by AgentScan |
aplatogg
left a comment
There was a problem hiding this comment.
Reviewed against your branch locally (PYTHONPATH pointed at your src/, pytest src/icalendar/tests/test_issue_2136_float_exponent.py src/icalendar/tests/prop): 1298 passed, 1 skipped. The approach is right and the output matches what #2136 asks for. Three points, in priority order.
1. news/2136.bugfix needs backticks around the roles. As written, the entry renders them as literal text instead of links:
Fixed :class:~icalendar.prop.float.vFloat writing values.
For Fixed :class:~... I rendered that through docutils and got the string back unchanged. Every other fragment in news/ writes :class:`~icalendar.prop.float.vFloat` and :rfc:`5545#section-3.3.7` with backticks, e.g. news/1084.bugfix. Both roles in that sentence need them.
2. inf/nan still write an invalid FLOAT, unchanged by this PR. vFloat(float("inf")).to_ical() is b'inf', which the grammar does not allow, because _float_to_ical only rewrites a repr that contains e. from_ical rejects those values, so nothing new is broken here, and I would keep the fix out of this PR. A math.isfinite() guard before formatting is where it would go if you want it later.
3. Optional, test placement. tests/prop/test_vFloat.py holds the vFloat tests and the vGeo assertions live in tests/prop/test_unit.py. A dedicated test_issue_2136_* file works, but folding the four cases into those two files may be what a maintainer asks for. No functional difference.
For the record, what I checked on your branch beyond the test suite: 0.1 -> b'0.1', so the shortest representation survives instead of expanding to full precision; 0.0 -> b'0.0'; -0.0 -> b'-0.0'; 1e16 -> b'10000000000000000'; 5e-324 writes 326 digits and parses back to the same float; vGeo((0.0, -0.0)) -> '0.0;-0.0'.
I had an independent PR for this (#2139) and closed it, so this is the only one open for #2136.
|
@fermsp do you need anything from us? It'd be good to finish this up and get it merged. Please let us know. Thank you! |
1c3d181 to
e5550f9
Compare
|
@stevepiercy sorry for the delay, nothing needed from you! This is my first contribution to an open source project, so I'm still learning the workflow. I applied your suggestion to the news fragment. Sorry also for the noise with the force push: I clicked "Update branch" by mistake and then reverted it, which dismissed @angatha's approval. The code is unchanged since that approval. The "Check built packages" job failed after 7 seconds on the previous push, before building anything, and |
|
@fermsp no worries. It's OK to update your branch against |
|
@fermsp I approved and enabled automerge. Thank you for your contribution to icalendar! |
Linked issue
Description
vFloat.to_ical()andvGeo.to_ical()wrote very small and very large numbers with an exponent, such asGEO:1e-05;-2e-05. The FLOAT value type of RFC 5545 has none. These values are now written with all their digits. Other values, xCal and jCal are unchanged.Checklist