▲ | unsnap_biceps 9 days ago | ||||||||||||||||
This is super exciting but I wish they added a function to render the template to a string rather then having everyone write their own version of basic rendering. | |||||||||||||||||
▲ | davepeck 9 days ago | parent | next [-] | ||||||||||||||||
One place we landed with PEP 750 is that Template instances have no natural string rendering. That is, you must process a Template in some way to get a useful string out the other side. This is why Template.__str__() is spec'd to be the same as Template.__repr__(). If you want to render a Template like an f-string for some reason, the pep750 examples repo contains an implementation of an `f(template: Template) -> str` method: https://github.com/davepeck/pep750-examples/blob/main/pep/fs... This could be revisited, for instance to add `Template.format()` in the future. | |||||||||||||||||
| |||||||||||||||||
▲ | nhumrich 9 days ago | parent | prev | next [-] | ||||||||||||||||
PEP 501 allowed `.format()` to do this, but discussions on PEP 750 felt that format shouldn't be needed, because when you need a basic format, you should probably just use f-strings. But maybe `__format__` can be added in in a future version of python if this is really wanted. | |||||||||||||||||
▲ | 9 days ago | parent | prev [-] | ||||||||||||||||
[deleted] |