Repository navigation
Conversation
tomschr
left a comment
There was a problem hiding this comment.
Thank you @echo666939 for your contribution. 👍❤️
I have a few suggestions. Could you look at them? Would love to hear your thoughts.
There was a problem hiding this comment.
fix looks correct for the truncation cases, and the test matrix covers cases my closed parallel attempt missed (signed zero, replace(), non-finite inputs). two notes in case either is useful:
-
pre-conversion validation as a possible simplification. in #533 i checked negativity on the original input before the lossy
int()call, with a TypeError-guarded comparison:try: is_negative = value < 0 except TypeError: is_negative = False
that also rejects negative numeric types outside the
Real/Decimalhierarchy (a customNumbersubclass whose< 0works and whose__int__truncates to zero), which the isinstance gate here doesn't cover. marginal case either way, just surfacing the difference. -
the repo's tests are pytest-style functions (see tests/test_semver.py), so matching that might cut review friction — maintainers' call though.
|
Thank you @SonicHedghog for your comments.
|
|
@tomschr, could you take another look at ee5d725? The changelog now uses the Sphinx exception role for I also addressed the numeric edge cases you and SonicHedghog raised. Integer conversion happens first, so a signaling The tests and documentation examples passed on Windows with Python 3.11 and 3.12 (667 passed, one optional-backend test skipped on each). Thanks for the review. |
|
Thank you @echo666939 for all the addition! 👍 From my side it looks good. Let's ask @SonicHedghog if he has some comments or suggestion. Thank you both of all the help! ❤️ |
There was a problem hiding this comment.
lgtm. skipping the comparison for exact int/str/bytes is right since int() preserves their sign, and the TypeError guard covers unordered SupportsInt objects. good validation order too. conversion first means nan and infinity keep their existing errors. nice work @echo666939
|
Ok, thanks to all. I added both of you in the "Co-authored-by" line. Happy to merge it. 🚀 |
Refs #531.
Version(-0.5)used to produce0.0.0. The constructor now checks both the converted integer and the sign of inputs that support a numeric comparison, including custom number types. Major, minor and patch all raiseValueErrorfor a negative part.Positive fractions retain their existing integer conversion. Signed zero and unordered objects with a valid
__int__remain supported. Integer conversion runs before the sign comparison, so NaN (including signaling Decimal NaN) and infinity retain their existing conversion errors.The regression tests use pytest and cover construction and
replace(). Four new cases failed on the previous PR revision and passed with this update. On Windows, the project tests and documentation examples passed on CPython 3.11.8 and 3.12.14 (667 passed, 1 optional native-backend test skipped on each). Coverage was disabled. The local runner loaded the two symlinked example modules from their target directory and shortened oversized pytest parameter IDs for Windows.AI assistance was used to develop and test this change.