-
Notifications
You must be signed in to change notification settings - Fork 6
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
Bikesheds #3
Comments
Re: Multi-string? I.e. is tag "a" "b" "c" allowed, presumably meaning tag "abc"? f-strings do not do this. If x=3, then f"{x}" "{x}" is "3{x}". |
Re: Space between tag and string literal? No, this is not possible with other prefixes. This also is a potential point of confusion where users may want to combine prefixes together, such as |
Yes. Note that for |
This is not in general reversible, though. We had this same issue with stringized annotations. It didn't matter there, since we weren't concerned with complete fidelity. >>> ast.dump(ast.parse("f'x={x!r}'"))
"Module(body=[Expr(value=JoinedStr(values=[Constant(value='x=', kind=None), FormattedValue(value=Name(id='x', ctx=Load()), conversion=114, format_spec=None)]))], type_ignores=[])"
>>> ast.dump(ast.parse("f'{x=}'"))
"Module(body=[Expr(value=JoinedStr(values=[Constant(value='x=', kind=None), FormattedValue(value=Name(id='x', ctx=Load()), conversion=114, format_spec=None)]))], type_ignores=[])" |
as opposed to requiring
Interestingly I haven't really being working with |
As I'm writing I'm finding the name "tag string" to be a bit awkward to use. I don't have the grammatical chops to justify it, but having two nouns right next to each other doesn't feel right to me. Given that, I think it would be better if we used the term "tagged string" as that uses an adjective to describe the string as being "tagged". This also aligns more closely with the name "f-string" which is meant to abbreviate "formatted string". For comparison, the JS equivalent is similarly called a "tagged template". I had also been using "string tag" to refer to the thing which interpolates a "tagged string". However, I think @jimbaker has been using "tag function" and, even though it could technically be an object with a |
@rmorshea So we have two choices for "tag string" per this insightful Wikipedia article on noun adjuncts, https://en.wikipedia.org/wiki/Noun_adjunct:
I had not really thought about this aspect of English before! |
In retrospect, I don't know why "tag function" was fine to my eye, but "tag string" was not, since they're effectively the same grammatical structure. Your original noun adjunct naming also has a nice symmetry I didn't appreciate before with the common "tag" prefix that we could use in naming other things. |
Also, while we're on the topic of naming, where did "Thunk" come from? I've been assuming it's a combination of "tuple" and "chunk", but I haven't seen any explicit reference to that. |
Thunk is a very old term used for a compiler-generated piece of code representing a parameter. It dates back to Algol-60 (of which I have very fond memories). https://en.wikipedia.org/wiki/Thunk |
There was a discussion on Lobste.rs today that lead to some interesting thoughts that seem closely related to this work, so I thought I would share: https://dotat.at/@/2020-09-17-generalized-string-literal-syntax-10-years-later.html |
Deleting/moving this comment from #20 I prefer a Single letter keywords, such as A couple of other benefits come to mind
|
The problem with
Obviously we can do something with this functionality with The advantage of using the tag string approach is that it is not currently valid syntax, so we can use it in this interesting way. |
But |
It seems a little hyperbolic to assume that's how people will react as I think that could be true of almost any change to the language. But regardless, this syntax has the advantage that Python already has string prefixes and that Javascript's template literals do the same, but with backticks. I'm not sure that we ruled out the possibility of using backticks, but that's another way this could be made visually distinct from normal string declarations. |
Yes, I will take care of that, along with other issues. There's too much that's been left open, and we can always reopen any if it comes up. |
Following this discussion for f-strings, it worth documenting that tagged strings can't be used as docstrings. |
Do you have a use case? |
Maybe:
Neither are really important. |
EDIT: @merwok explained that I should go somewhere else with my questions, editing the post so I (hopefully) don't disturb more people than I already have! |
The right place would be here I think: https://discuss.python.org/t/allow-for-arbitrary-string-prefix-of-strings/19740/6 This tracker (I think) is used to work out some issues between the people working on the proposal, and this ticket specifically is for some cosmetic details («bikesheds») and not the project in general. Hope this helps! |
Eventually these may each need their own issue? For now, some bullets, some with recommendations.
Syntax
tag "abc"
the same astag"abc"
? [rec: disallow]tag"abc"
ortag "abc"
?tag"a" "b" "c"
allowed, presumably meaningtag"abc"
? [rec: disallow]tag r"abc"
-- but perhaps we should not interpret backslashes? I.e.tag "\a\b\c"
would call effectivelytag(r"\a\b\c")
, i.e. a string of six characters.foo().tag"abc"
)? [rec: single name only]tag "abc" [i]
? (You can writef"xyz"[i]
.) [rec: yes]{x!r}
,{x!s}
,{x!a}
,{x = }
? [rec: yes]len"foo"
(which is the same aslen("foo")
). I'm guessing that's why JavaScript uses backticks for tagged templates?Semantics
Thunk
class.The text was updated successfully, but these errors were encountered: