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
Initial specification PEP #17
base: main
Are you sure you want to change the base?
Conversation
Another inspiration, if you want more than js tagged template literals, are sigils in Elixir: https://elixir-lang.org/getting-started/sigils.html |
Hm. That sounds like something quite different. Here's an example from the page you link -- these are all ways to spell the same regex:
I don't think Python is looking for this level of strangeness. |
We could certainly point to it as an example of another language which has a similar feature. However, sigils differ syntactically, as Guido pointed out, as well as from the perspective of implementation because (from what I can tell) interpolation is achieved by defining the sigil as a macro. |
I should have linked to the custom sigils part at the end of the document: https://elixir-lang.org/getting-started/sigils.html#custom-sigils where you type ~tag"something" and can have a custom method sigil_tag that runs any code based on that. It was not a suggestion to follow their lead, but a way to say that JS is not alone in having support for "tag functions". |
.. code-block:: python | ||
|
||
brothers = 'Click & Clack' | ||
s = f'<div>Hi, {brothers}!/>' |
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 think this is meant to be:
s = f'<div>Hi, {brothers}!/>' | |
s = f'<div>Hi, {brothers}!</div>' |
from html import escape | ||
|
||
brothers = 'Click & Clack' | ||
s = f'<div>Hi, {escape(brothers)}!/>' |
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.
s = f'<div>Hi, {escape(brothers)}!/>' | |
s = f'<div>Hi, {escape(brothers)}!</div>' |
from my_htmllib import html | ||
|
||
brothers = 'Click & Clack' | ||
dom = html'<div>Hi, {brothers}!/>' |
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.
dom = html'<div>Hi, {brothers}!/>' | |
dom = html'<div>Hi, {brothers}!</div>' |
title = 'President & CEO' | ||
|
||
dom = html""" | ||
<div>Hi, {name}, you have {amount:formatspec} |
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.
<div>Hi, {name}, you have {amount:formatspec} | |
<div>Hi, {name}, you have {amount:formatspec}</div> |
I managed to find this articular from TC39 (the ECMAScript standards organization) unfortunately the link to the full proposal is broken and I've been unable to find it - this list of finished proposals doesn't go back to 2015 when the template strings were originally accepted. The proposal's original champion, Mike Samuel, is still around though. Might be worth reaching out to see if he has any information on the original proposal that we could take advantage of. |
@rmorshea It seems template strings were called Quasi-literals before, so the spec is tied to that name. Also seems the site where the specification was hosted is down. Luckily, web archive saves the day, with this save link from 2017: https://web.archive.org/web/20170114115928/wiki.ecmascript.org/doku.php?id=harmony:quasis It's similar in content to this blog post which is still up: https://2ality.com/2011/09/quasi-literals.html |
@jimbaker I believe we've incorporated everything we can from this PR and the discussion. I propose closing the PR. |
No description provided.