-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
PEP 750: restrict support for Template
+ str
addition
#4395
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
base: main
Are you sure you want to change the base?
Conversation
Adding the label to prevent inadvertent merging before pronouncement |
template = t"Hello " + Template(Interpolation(name, "name")) | ||
|
||
Python's implicit concatenation syntax is supported between any combination | ||
of ``Template`` and ``str``: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it shouldn't be more explicit that the str
is a literal string, not the result of an f-string expression? See this conversation:
sql_string = t"SELECT id,name "
t"FROM users "
f"WHERE name={col}" # 1-chart typo causing injection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent was to continue to allow t"" f""
. We should definitely explicitly mention it in the PEP edit.
As mentioned in Python discuss, either we keep both t"" ""
and t"" f""
implicit concatenation, or we drop both.
The proposed change to the PEP keeps them, with the view that t"" ""
is plausibly useful, and t"" f""
is both rare and trivially lintable. It also acknowledges that there may be real implementation risk in removing some kinds of implicit concat while retaining others (aka ”” f””
should continue to work) — risk that may simply be beyond what is acceptable at this late stage.
An argument to instead drop both forms of implicit concatenation would be: "hey, why should any form of literal construction of t-strings, no matter how uncommon, lead to a plausible injection?"
PEP 123: Summary of changes
)Following this PR opened with the steering-council and related discussion, we propose an update to PEP 750 that:
Template.__radd__
entirelystr
inTemplate.__add__
A rationale is provided and the two relevant sections of the PEP are updated (
"Template String Concatenation"
and, in rejected ideas,"Disallowing Template Concatenation"
).📚 Documentation preview 📚: https://pep-previews--4395.org.readthedocs.build/