Skip to content
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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Initial specification PEP #17

wants to merge 3 commits into from

Conversation

jimbaker
Copy link
Owner

@jimbaker jimbaker commented Sep 5, 2022

No description provided.

pep.rst Outdated Show resolved Hide resolved
@EmilStenstrom
Copy link

EmilStenstrom commented Jan 9, 2023

Another inspiration, if you want more than js tagged template literals, are sigils in Elixir: https://elixir-lang.org/getting-started/sigils.html

@gvanrossum
Copy link
Collaborator

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:

~r/hello/
~r|hello|
~r"hello"
~r'hello'
~r(hello)
~r[hello]
~r{hello}
~r<hello>

I don't think Python is looking for this level of strangeness.

@rmorshea
Copy link
Collaborator

rmorshea commented Jan 10, 2023

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.

@EmilStenstrom
Copy link

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}!/>'

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:

Suggested change
s = f'<div>Hi, {brothers}!/>'
s = f'<div>Hi, {brothers}!</div>'

from html import escape

brothers = 'Click & Clack'
s = f'<div>Hi, {escape(brothers)}!/>'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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}!/>'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dom = html'<div>Hi, {brothers}!/>'
dom = html'<div>Hi, {brothers}!</div>'

title = 'President & CEO'

dom = html"""
<div>Hi, {name}, you have {amount:formatspec}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<div>Hi, {name}, you have {amount:formatspec}
<div>Hi, {name}, you have {amount:formatspec}</div>

@rmorshea
Copy link
Collaborator

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.

@EmilStenstrom
Copy link

EmilStenstrom commented Apr 23, 2023

@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

@pauleveritt
Copy link
Collaborator

@jimbaker I believe we've incorporated everything we can from this PR and the discussion. I propose closing the PR.

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

Successfully merging this pull request may close these issues.

None yet

6 participants