Skip to content

Fix test_chr by raising a ValueError on chr(-1) instead of OverflowError - #3223

Merged
youknowone merged 1 commit into
RustPython:mainfrom
pheki:fix-test-chr
Oct 5, 2021
Merged

youknowone merged 1 commit into
RustPython:mainfrom
pheki:fix-test-chr

Conversation

@pheki

@pheki pheki commented Oct 5, 2021

Copy link
Copy Markdown
Contributor

test_chr used to fail on chr(-1) because it would fail to convert the -1 to u32 in try_to_primitive, raising an OverflowError.

By changing the received value to a BigInt, we're able to match chr's docs and always raise a ValueError if the value is out of range. Note that CPython in turn may raise an OverflowError if the argument is too high (platform dependent as it depends on int size), even if it's not documented anywhere.

Another option would be to change the received value to i32.

Comment thread vm/src/stdlib/builtins.rs Resolved

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing!

@youknowone
youknowone merged commit d2fe6e8 into RustPython:main Oct 5, 2021
@pheki
pheki deleted the fix-test-chr branch October 5, 2021 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants