Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Implement str.format() #171

Open
trotterdylan opened this issue Jan 19, 2017 · 4 comments
Open

Implement str.format() #171

trotterdylan opened this issue Jan 19, 2017 · 4 comments

Comments

@trotterdylan
Copy link
Contributor

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

@S-YOU
Copy link
Contributor

S-YOU commented Jan 20, 2017

Yeah, hit that a lot when adding new modules.

@S-YOU
Copy link
Contributor

S-YOU commented Jan 20, 2017

I think we have three options.

What would be Ideal solution? I guess CPython version?

@trotterdylan
Copy link
Contributor Author

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.

@S-YOU
Copy link
Contributor

S-YOU commented Jan 21, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants