-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add format builtin and String formatting stuff. #231
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
Conversation
This includes everything needed to call str.format with integers as positional and keyword parameters.
@@ -107,6 +107,16 @@ impl VirtualMachine { | |||
self.new_exception(value_error, msg) | |||
} | |||
|
|||
pub fn new_key_error(&mut self, msg: String) -> PyObjectRef { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of String
the preferred type is more &str
since this will allow you to pass string arguments with the .to_string()
suffix. This is a minor detail though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying to match the other new_xxx_error functions. I can go ahead and change them all to take a string slice if that's better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is very good. Leave it like this, it can be done later, it is not important now.
# String Formatting | ||
assert "{} {}".format(1,2) == "1 2" | ||
assert "{0} {1}".format(2,3) == "2 3" | ||
assert "--{:s>4}--".format(1) == "--sss1--" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!
Nice job! This is a really good improvement to rustpython. Please run some formatting on the code. As well, you might need to add |
We should add support for '\t', but that should probably be a separate ticket.
The parser currently doesn't handle missing newline gracefully.
I'm playing around with handling tabs followed by spaces, and nixing everything else. I'm poking at what python3 does. It's definitely stricter than Python2 |
I made #234 for the tabs/spaces issue. |
This includes everything needed to call str.format with integers as positional and keyword parameters.
Partially resolves #162.
Not implemented: float formatting, the format method of str.