This idea by jdveiga seems like a good one.  It doesn't require any change in Python, although conceivably an informational PEP could make some specific convention a recommendation.

The thing is, SQL isn't THAT special.  I use SQL a lot myself, so would benefit from such support.  But there are LOTS of mini-languages that I might work with as strings in Python.  Pandas queries; Numexpr transformations; XPath queries; HTML; Regex; MongoDB queries; JSON query (which I think is mostly the same as MongoDB); LDAP query; GraphQL; and lots of others.

I certainly don't want to make new string types for every one of these.  And I don't even want special syntax to allow an arbitrary string style.  In concept, something like an f-string declaration might be possible:

query = f"{SELECT * FROM table|@sql}"

I'm not sure if that off-the-cuff "suggestion" would be possible in Python's parser, but just to show the vague idea.  But a comment convention feels much lighter here.

On Fri, Feb 21, 2020 at 10:16 AM <jdveiga@gmail.com> wrote:
May I suggest mark string with comments instead of populating the interpreter with lost of "string" templates?

Something like
"SELECT * FROM table"  # string: sql

Or
"<p><strong>spam</strong> ham eggs</p>  # template: html


IDEs can read this comment and highlight (and do some other static checks) on the commented strings.

It can be easily combined with raw strings and f-strings such as:

f"<p><strong>{my_string}</strong> ham</p>"  # doctype: html
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/7FWPN7GFZNRQ7YCV35DJAOSL7XKXIFMM/
Code of Conduct: http://python.org/psf/codeofconduct/


--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.