SethMMorton / fastnumbers

Super-fast and clean conversions to numbers for Python.
https://pypi.org/project/fastnumbers/
MIT License
105 stars 13 forks source link

Use std::variant and std::optional make error handling simpler #66

Closed SethMMorton closed 1 year ago

SethMMorton commented 1 year ago

Change error handling from "check the state after calling" to "I'm returning a type that forces you to check for errors to use it, haha". Doing this enables more const-correctness because state no longer needs to be stored, so parsing objects can be const.

Heavy use of the visitor pattern is now used to handle error checking.

Hopefully this change also improves coverage.

codecov[bot] commented 1 year ago

Codecov Report

Base: 92.86% // Head: 94.42% // Increases project coverage by +1.55% :tada:

Coverage data is based on head (cdcd3b2) compared to base (99c04cb). Patch coverage: 94.37% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #66 +/- ## ========================================== + Coverage 92.86% 94.42% +1.55% ========================================== Files 20 16 -4 Lines 1907 1705 -202 Branches 267 238 -29 ========================================== - Hits 1771 1610 -161 + Misses 23 21 -2 + Partials 113 74 -39 ``` | [Impacted Files](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton) | Coverage Δ | | |---|---|---| | [include/fastnumbers/parser/base.hpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-aW5jbHVkZS9mYXN0bnVtYmVycy9wYXJzZXIvYmFzZS5ocHA=) | `85.71% <66.66%> (-9.94%)` | :arrow_down: | | [include/fastnumbers/parser/numeric.hpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-aW5jbHVkZS9mYXN0bnVtYmVycy9wYXJzZXIvbnVtZXJpYy5ocHA=) | `80.00% <85.71%> (-13.26%)` | :arrow_down: | | [src/cpp/implementation.cpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-c3JjL2NwcC9pbXBsZW1lbnRhdGlvbi5jcHA=) | `98.36% <85.71%> (+0.47%)` | :arrow_up: | | [src/cpp/extractor.cpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-c3JjL2NwcC9leHRyYWN0b3IuY3Bw) | `94.02% <93.02%> (+1.62%)` | :arrow_up: | | [include/fastnumbers/ctype\_extractor.hpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-aW5jbHVkZS9mYXN0bnVtYmVycy9jdHlwZV9leHRyYWN0b3IuaHBw) | `95.04% <93.10%> (+1.88%)` | :arrow_up: | | [include/fastnumbers/evaluator.hpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-aW5jbHVkZS9mYXN0bnVtYmVycy9ldmFsdWF0b3IuaHBw) | `86.74% <100.00%> (+12.01%)` | :arrow_up: | | [include/fastnumbers/iteration.hpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-aW5jbHVkZS9mYXN0bnVtYmVycy9pdGVyYXRpb24uaHBw) | `86.66% <100.00%> (+0.52%)` | :arrow_up: | | [include/fastnumbers/parser/character.hpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-aW5jbHVkZS9mYXN0bnVtYmVycy9wYXJzZXIvY2hhcmFjdGVyLmhwcA==) | `92.50% <100.00%> (-1.50%)` | :arrow_down: | | [include/fastnumbers/parser/unicode.hpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-aW5jbHVkZS9mYXN0bnVtYmVycy9wYXJzZXIvdW5pY29kZS5ocHA=) | `75.51% <100.00%> (-20.65%)` | :arrow_down: | | [include/fastnumbers/resolver.hpp](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton#diff-aW5jbHVkZS9mYXN0bnVtYmVycy9yZXNvbHZlci5ocHA=) | `100.00% <100.00%> (+1.92%)` | :arrow_up: | | ... and [19 more](https://codecov.io/gh/SethMMorton/fastnumbers/pull/66?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton) | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seth+Morton)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.