Skip to content

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

Merged
merged 4 commits into from
Dec 17, 2018

Conversation

johndaniels
Copy link
Contributor

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.

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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--"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job!

@windelbouwman
Copy link
Contributor

Nice job! This is a really good improvement to rustpython. Please run some formatting on the code. As well, you might need to add \t support to the lexer I noticed.

We should add support for '\t', but that should probably be a separate ticket.
The parser currently doesn't handle missing newline gracefully.
@johndaniels
Copy link
Contributor Author

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

@johndaniels
Copy link
Contributor Author

I made #234 for the tabs/spaces issue.

@windelbouwman windelbouwman merged commit 1b13b0c into RustPython:master Dec 17, 2018
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.

Implement the builtin format function.
2 participants