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

PEP 536: Final Grammar for Literal String Interpolation #155

Merged
merged 1 commit into from
Dec 14, 2016
Merged

PEP 536: Final Grammar for Literal String Interpolation #155

merged 1 commit into from
Dec 14, 2016

Conversation

flying-sheep
Copy link
Contributor

@flying-sheep flying-sheep commented Dec 10, 2016

Hi, I announced some time ago that I’d pick this up, now I’ve finally managed to write it!

I hope the general structure, phrasing, formatting and so on are OK, this is my first PEP.

rendered

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

Unfortunately we couldn't find an account corresponding to your GitHub username at bugs.python.org (b.p.o). If you don't already have an account at b.p.o, please create one and make sure to add your GitHub username. If you do already have an account at b.p.o then please go there and under "Your Details" add your GitHub username.

And in case you haven't already, please make sure to sign the PSF contributor agreement (CLA); we can't legally look at your contribution until you have signed the CLA.

Once you have done everything that's needed, please reply here and someone will verify everything is in order.

@flying-sheep
Copy link
Contributor Author

flying-sheep commented Dec 10, 2016

I signed the CLA and put my github name!

I’d also love if #1 could be fixed. would make it easy to provide a “rendered view” link like it’s common for rust RFCs

@flying-sheep flying-sheep changed the title Added f-literals PEP draft PEP ???: Final Grammar for Literal String Interpolation Dec 10, 2016
@brettcannon
Copy link
Member

Please wrap the lines at 70 or 79 characters (I haven't looked at the content).

@flying-sheep
Copy link
Contributor Author

done! some code that i copied from PEP 498 needs to be longer.

Version: $Revision$
Last-Modified: $Date$
Author: Philipp Angerer <[email protected]>
Status: Pending
Copy link
Member

Choose a reason for hiding this comment

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

Could you change this to Draft so Travis testing will pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@brettcannon
Copy link
Member

Looks like Travis is still not happy yet.

@flying-sheep
Copy link
Contributor Author

on it. apparently you have to give it a number anyway. maybe it would make sense to provide a way to get a number before a PEP or so.

Copy link
Member

@berkerpeksag berkerpeksag left a comment

Choose a reason for hiding this comment

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

The .rst extension doesn't work with python.org yet. Could you change it to .txt please?

@@ -0,0 +1,175 @@
PEP: 999
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason to use 999? I think we can use the next available number: 536 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PEP 12 says i have to be given one, not just pick the next one, but it seems reasonable. maybe we should fix this in PEP 12 and fix conflicts if people try to use the same number.

PEP 12 also says we can use rst already…

Copy link
Member

Choose a reason for hiding this comment

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

PEP 12 also says we can use rst already…

That's my fault. I thought I can finish my work by now, but due to some personal issues I couldn't find the time to work on it yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't worry and I hope everything works out for you!

Created: 20-Sep-2016
Python-Version: 3.7
Post-History: 20-Sep-2016
Resolution: None
Copy link
Member

Choose a reason for hiding this comment

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

This is optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean? can i just leave out the “Resolution” line?

Copy link
Member

Choose a reason for hiding this comment

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

There is no point to keep an optional field now (and I don't think using None as a value makes any sense) We can always add it back when your PEP is discussed on python-ideas :)

Content-Type: text/x-rst
Created: 20-Sep-2016
Python-Version: 3.7
Post-History: 20-Sep-2016
Copy link
Member

Choose a reason for hiding this comment

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

You probably want to update this date :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Rosuav
Copy link
Contributor

Rosuav commented Dec 12, 2016

PEP 12 probably needs some updates for the new GitHub workflow. Having a contributor pick a PEP number is unlikely to have conflicts (it's not common to see two new PEPs proposed simultaneously), and as soon as one's merged, the other would show a merge conflict in git. So it's safe.

@flying-sheep
Copy link
Contributor Author

@berkerpeksag all done

@flying-sheep flying-sheep changed the title PEP ???: Final Grammar for Literal String Interpolation PEP 536: Final Grammar for Literal String Interpolation Dec 12, 2016
it is easy to extend syntax highlighters to correctly parse
and display f-literals:

.. raw:: html
Copy link
Member

Choose a reason for hiding this comment

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

python.org (django-markitup to be exact) ignores the raw directive for security reasons. Can you change this to a plain code block?

Copy link
Contributor Author

@flying-sheep flying-sheep Dec 12, 2016

Choose a reason for hiding this comment

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

@sadly no. the whole point is to show this specific syntax highlighting.

are you sure python.org does this? i don’t see markitup in use here.

if it does though: PEPs are trusted. we can simply set raw_enabled to True. or we do it and use bleach to sanitize the HTML.

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be more interesting to actually include the diff of what you had to change to the syntax highlighter to make it work than the actual output as the critical aspect of your claim is it's easy to update highlighters, not that it works in the end (we can just take your word on that).

As for removing the protection, I don't think we should change how python.org functions just for this one thing (we've gone 16 years and hundreds of PEPs without allowing raw HTML and this specific example is not critical to the PEP itself anyway).

Copy link
Contributor Author

@flying-sheep flying-sheep Dec 13, 2016

Choose a reason for hiding this comment

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

I think it would be more interesting to actually include the diff of what you had to change to the syntax highlighter to make it work

good idea, i’ll add that part!

than the actual output

seeing is believing! i really want to include that part for people who have only seen string-colored code parts until now instead of something like this!

pep-0999-1

I don't think we should change how python.org functions just for this one thing

actually @berkerpeksag was mistaken and we don’t have to change a thing. generate_pep_pages.py says:

Run this command AFTER normal RST -> HTML PEP transformation from the PEP
repository has happened. This works on the HTML files created during that
process.

with “works”, it means “runs get_pep_page” on the paths of the generated PEP HTML fragments…

…and pep2html.py happily embeds my raw HTML

Copy link
Member

Choose a reason for hiding this comment

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

Good catch! I just tried this branch in my local python.org setup and it worked fine. I forgot we only store HTML outputs in the database. Thanks!

The only thing we need is to rename the file name to pep-0536.txt (add a leading zero like the other PEPs)

I haven't fully read the PEP yet so I'll let Brett or Chris do the proofreading and the merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops! done, the zero’s there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brettcannon i added a paragraph about syntax highlighter implementation

Rationale
=========

.. https://mail.python.org/pipermail/python-ideas/2016-August/041727.html
Copy link
Member

Choose a reason for hiding this comment

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

This link should be at the References section, and add the thread title here (Let’s make escaping in f-literals impossible)

As mentioned in PEP 12 :)
https://www.python.org/dev/peps/pep-0012/#hyperlinks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ATM it’s just a comment, but i can add it as link if you want.

by giving f-literals a regular grammar without exceptions
and implementing it using dedicated parse code.

.. note:: put preceding paragraph into “Rationale”?
Copy link
Member

Choose a reason for hiding this comment

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

Should probably decide if you're going to follow through with this comment or simply remove it now as there's no need to wait on feedback for a decision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Familiarity also plays a role: Arbitrary nesting of expressions
without expansion of escape sequences is available in every single
other language employing a string interpolation method that uses
expressions instead of just variable names. [#]_
Copy link
Member

Choose a reason for hiding this comment

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

Do give names to your references, else it's easy to get the sequence wrong if you add a reference later on.

Python challenge”
#. Syntax highlighters are good in parsing nested grammar, but not
in recognizing escape sequences. ECMAScript 2016 (JavaScript) allows
escape sequences in its identifiers [#]_ and the author knows of no
Copy link
Member

Choose a reason for hiding this comment

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

Please name your references as its easy for the order to change if you add a reference later.

Copy link
Contributor Author

@flying-sheep flying-sheep Dec 14, 2016

Choose a reason for hiding this comment

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

done!

in expression portions of single line strings.

.. note:: Is lifting of the restrictions sufficient,
or should we specify a more complete grammar?
Copy link
Member

Choose a reason for hiding this comment

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

An actual diff of Python's Grammar/Grammar file would be best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could you point me to another PEP where this is done so i have a reference?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know of a specific one off the top of my head. You're going to have to do this for the implementation anyway and so you can just embed the diff to the grammar file.

Reference Implementation
========================

TBD
Copy link
Member

Choose a reason for hiding this comment

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

Is an implementation being worked on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not yet. isn’t the usual procedure to wait for feedback first?

Copy link
Member

Choose a reason for hiding this comment

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

The usual procedure is to ask on python-ideas if the idea seems viable, and then if it does then you do a draft PEP to python-ideas, and then if it holds up you do a rough implementation and send it along with the PEP to python-dev because that's when the question of maintenance comes into play.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. in this case people already confirmed that they think this is a good idea, but i never coded anything in C. so where do i turn to for guidance?

Copy link
Member

Choose a reason for hiding this comment

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

Either you ask for help upfront when you post your PEP to python-ideas and end up with a co-author or you hope that python-dev thinks your idea is so good that a core dev agrees to do it for you (but that's not very common).

@brettcannon
Copy link
Member

I just realized I don't remember seeing this PEP sent to python-ideas and I forgot to ask that. So has this gone to python-ideas first for discussion prior to opening this PR?

@flying-sheep
Copy link
Contributor Author

no, but the idea was born in a thread there, and all arguments already came up

not in comprehensive PEP form though

@brettcannon brettcannon merged commit 64eebdf into python:master Dec 14, 2016
@brettcannon
Copy link
Member

Since you need the PEP to ask for help I've gone ahead and accepted the PEP. Before you send it to python-ideas, @flying-sheep , please fork the repository and have people send changes directly to you. Once the discussion is finished on python-ideas you can send us another PR to incorporate the accumulated changes from the python-ideas discussion.

@flying-sheep flying-sheep deleted the f-literals branch December 15, 2016 14:22
@flying-sheep
Copy link
Contributor Author

OK, thank you! will do.

i’ll tell them to comment on https://github.com/flying-sheep/peps/blob/master/pep-0536.txt

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

Successfully merging this pull request may close these issues.

6 participants