Skip to content

Implement str.format() #29

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

Open
alanjds opened this issue Aug 21, 2018 · 4 comments
Open

Implement str.format() #29

alanjds opened this issue Aug 21, 2018 · 4 comments
Labels
imported Imported from google/grumpy

Comments

@alanjds
Copy link

alanjds commented Aug 21, 2018

google#171 opened by @trotterdylan commented on 19 Jan 2017

There's a lot stdlib code (especially in the unittest library) that uses str.format() so this will become very important soon.

@alanjds
Copy link
Author

alanjds commented Aug 21, 2018

Comment by S-YOU
Friday Jan 20, 2017 at 01:16 GMT


Yeah, hit that a lot when adding new modules.

@alanjds
Copy link
Author

alanjds commented Aug 21, 2018

Comment by S-YOU
Friday Jan 20, 2017 at 03:08 GMT


I think we have three options.

What would be Ideal solution? I guess CPython version?

@alanjds
Copy link
Author

alanjds commented Aug 21, 2018

Comment by trotterdylan
Friday Jan 20, 2017 at 17:35 GMT


I think newformat will be problematic because of all the pypy specific extensions used in that file.

The stringformat lib is a good find! It would require a little hackery because the grumpy Go package would need to somehow patch str.format with the generated code for stringformat.py. But it is doable and it could be a good stopgap until we can implement something ourselves.

@alanjds
Copy link
Author

alanjds commented Aug 21, 2018

Comment by S-YOU
Saturday Jan 21, 2017 at 03:27 GMT


Monkey-patching method on builtins is easier on grumpy than (CPython](https://gist.github.com/mahmoudimus/295200)

Can we keep as a feature or will forbid like CPython?

str.__dict__["format"] = lambda self: "formatted: " + self
print "hello".format()
formatted: hello

@alanjds alanjds added the imported Imported from google/grumpy label Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported Imported from google/grumpy
Projects
None yet
Development

No branches or pull requests

1 participant