Skip to content

PyInt.format only raises ValueError #4428

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

Merged
merged 5 commits into from
Jan 7, 2023

Conversation

yt2b
Copy link
Contributor

@yt2b yt2b commented Jan 7, 2023

#4387
I've fixed to raise OverflowError.

>>>>> f"{-1:c}"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: %c arg not in range(0x110000)

@yt2b yt2b marked this pull request as ready for review January 7, 2023 07:41
@@ -271,6 +271,8 @@ fn parse_precision(text: &str) -> Result<(Option<usize>, &str), &'static str> {
}

impl FormatSpec {
pub const NOT_IN_RANGE: &str = "%c arg not in range(0x110000)";
Copy link
Member

Choose a reason for hiding this comment

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

We'd better to define a new enum for this type.

enum FormatSpecError {
     ...
}

impl IntoPyException for FormatSpecError {
   ...
}

This is also a possible fix of the problem, but I'd more like to avoid string comparison to decide the error type from python side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code fix completed.

@yt2b yt2b force-pushed the raise_overflow_error branch from 2b489b9 to 1e99eec Compare January 7, 2023 14:35
@youknowone youknowone merged commit 22a5a83 into RustPython:main Jan 7, 2023
@yt2b yt2b deleted the raise_overflow_error branch January 9, 2023 04:00
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.

2 participants