Better `repr` for `string.templatelib.Template`.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Proposal:
Currently the repr output for template strings shows how the data is stored internally, but this is not how the template could be reconstructed via an constructor call and the format is unintuitive since the template parts are not output in the order they appear in the template source. The repr result should output the parts in the order as iterating over the template object does, i.e.
x = 1
y = 2
print(repr(t'{x} + {y}'))
should print
Template(Interpolation(1, 'x', None, ''), ' + ', Interpolation(2, 'y', None, ''))
instead of
Template(strings=('', ' + ', ''), interpolations=(Interpolation(1, 'x', None, ''), Interpolation(2, 'y', None, '')))
This has already been discussed at https://discuss.python.org/t/repr-output-of-t-strings/107653
I'm working on a patch/pull request.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/repr-output-of-t-strings/107653
Linked PRs
- gh-151104
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the string.templatelib.Template repr behavior described in the issue and compare it with iteration over a template object. Verify that repr outputs Template parts in iteration order and matches the proposed constructor-call format; gh-151104 is linked, so review that work before starting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100