Re: Extract variable name from itself

Since I wrote that commit: no one is saying it’s impossible or overly difficult,
To be honest it is exactly what was being said.
just that the benefit of having it doesn’t justify the cost of adding it. I can understand that.
I understand that you think it’s worth the cost. No, I don’t think that. I wrote here to find that out.
What I think is that it would be an elegant feature if it was implemented at python level. Thanks for reply, DG

Dom Grigonis writes:
To be honest it is exactly what was being said.
Sure ... about an unclearly expressed early version of the proposal, that seemed to ask "given an object x, tell me the name of x". In the end, I don't think there was any disagreement that doing that reliably is indeed impossible. But if someone has written that the #nameof version of the proposal is impossible to implement, that is not representative of what most of us think or have said.
What I think is that it would be an elegant feature if it was implemented at python level.
The postfix '=' flag is elegant by anyone's standard, I think: it provides immediately useful, though limited, functionality, with no waste, and is automatically fit for purpose because it satisfies DRY. And it is mnemonic in the sense that you may have to look it up to write it, but once you've learned it, you will recognize it when you see it in unfamiliar code because it "looks like" what it produces. The proposed prefix '=' flag is much less attractive to me on all counts above, except that it's quite mnemonic. Steve

I haven’t given much thought regarding the syntax. The prefix “=“ just popped into my mind and I went along with it to use in my examples. The point was that f-strings are potentially a good place to implement such thing. By “elegant", I wasn’t talking about the syntax. It was more about the benefits of it being well integrated python construct, which is subject to a parser and is a python code by all standards and it fitting in that place sensibly given what it is. Regards, DG

Dom Grigonis writes:
By “elegant", I wasn’t talking about the syntax.
Neither was I, except in the comment about "mnemonic". I use "postfix =" and "prefix =" because I don't know of better names that indicate the semantics of the feature. Semantically, "prefix =" is a reasonable solution to the problem -- assuming you consider it a problem. But it's far from concise and violates DRY -- it doesn't solve the problem of the first draft typo. I don't see it as elegant the way "postfix =" is.

Dom Grigonis writes:
But it's far from concise What could be more concise?
A notation where you don't have to repeat a possibly long expression. For example, numerical positions like regular expressions. Consider this possible notation: f'There are {count} expression{pluralize(count)} denoted by {=0}.' Otherwise it isn't great, but it's definitely concise. In the simplest case you could omit the position: f'{=} is {count} at this point in the program.'
and violates DRY -- it doesn't solve the problem of the first draft typo.
And how is “postfix =“ different?
You *can't* use different identifiers for the name and value in "postfix =": the same text is used twice, once as a string and one as an identifier.

On Mon, 25 Sept 2023 at 00:15, Dom Grigonis <dom.grigonis@gmail.com> wrote:
What do you mean by that? Are you suggesting that there's a massive cost in constructing a string literal and thus reusing it with .format() is more efficient than an f-string? Because that's, uhh, kinda not the point of str.format(). And if that isn't what you mean, what is it? Your posts are often distinctly unclear. I get the impression that you think everyone else understands your idea. ChrisA

or print('{a=} and b={a}') This already exists. Kindly stop reinventing the wheel. the thing that does not exist now is: print('In this context, variable', 'name', 'means an esoteric thing that we all know about') where `'name'` can be substituted easily (the 'nameof' case) but it could be, as an example: print('In this context, variable {name!i} means an esoteric thing that we all know about') (my favorite, but interpreter maintenance costs trumps my preferences) or could be done as: print('In this context, variable', typing.ID['name'], 'means an esoteric thing that we all know about') which wouldn't change the interpreter at all, (but would change the stdlib). Either way, the 'nameof'-support needs editor support, because it is an *editing* use case, the interpreter just doesn't care. (It could, but it *can't* do anything without the *editor* responding to it) Em dom., 24 de set. de 2023 às 11:13, Dom Grigonis <dom.grigonis@gmail.com> escreveu:

I think the separation is needed between the 2: a) identifier name b) expression text I think there is a mix-up between these 2 which causes some confusion (at least to me). Wanting both made me cling to f-strings as they currently do b) in ‘postfix=' and a) can be extracted from it. ————— I think having b) will be convenient to extract given/when/if/please deferred evaluation is implemented: a = `expr` print(a.__expr_text__) # ‘expr' ————— So I think the focus here is a). I think this is what you are having in mind, while I think about both - thus slight miscommunication. And for it I currently see 3 options: 1. typing.ID['name'] I think this one is too verbose for what it is. Also requiring an import 2. ‘{name!i}’ This one is sensible (and I think is better than my prefix=) 3. nameof(name) But I am leaning towards this one. Pros: * it is not coupled with either string formatting or typing. * C# guys most likely gave some thought into it so the resulting output can potentially be modelled after it. That is: to either return identifier name, or the name of the attribute. * Also, this would be in line with your suggestion of not reinventing the wheel. * Finally, there would be no extra editor work. Cons: * Extra name in global namespace * Any thoughts why this isn’t a good option? Regards, DG

There definitely is a miscommunication: The 2 first options was me spitballing an alternative against the third. The not reinventing the wheel remark was me saying that the particular example that you gave *on that particular message* can already be done. Also the case 2 f'{name!i}', I suggested as an extension of the current formatting paradigm, but is also the same as `f{name=}` except that you don't format the *value*, so I *imagine* (that word pulling more weight than I do at the gym, mind you) would be trivial to implement. It *needs* editor support regardless. While I would be very glad if my opinion is adopted by the community, do not substitute my opinion for the community's. Em dom., 24 de set. de 2023 às 12:29, Dom Grigonis <dom.grigonis@gmail.com> escreveu:

I have no problems with either b) or c), but I like c) better. As you said: print('In this context, variable', 'name', 'means an esoteric thing that we all know about’) Maybe it would be sensible not to couple ‘esoteric` thing with non-esoteric ones and find its place among other unique functionality providing things, such as id, type, exec, etc.

Appling my specific advice elsewhere is at most cute, in this case it was offensive, and I doubt it was only to me. The `'f{name!id}'` syntax is what *I* prefer, but *I* think that subclassing typing.LiteralString is less disruptive. 'Esoteric' means something hidden, it is the exact opposite of 'we all know about' Em dom., 24 de set. de 2023 às 16:11, Dom Grigonis <dom.grigonis@gmail.com> escreveu:

'Esoteric' means something hidden, it is the exact opposite of 'we all know about' What I meant is that functions in __builtins__ are low level, with functionality which is hidden from the user. So my point is that it seems like an appropriate place for nameof(). After all, f’{v!<fmt>}’ applies functions to v from builtin namespace: str/repr/ascii.

On Mon, 25 Sept 2023 at 10:05, Dom Grigonis <dom.grigonis@gmail.com> wrote:
My position is that so far, you haven't shown it to be of much value. Which might be because the idea has no value, but more likely, it's because I just haven't understood from your posts why this should be added to the language. So far, you've shown that this should be an editor feature, but you haven't convinced me that the language should take any notice of it. ChrisA

I think a lot has been said by this time and I have nothing to add. If this is something that is of value, I am sure it will be picked up when the time is right. One last thing that I think could be of some use is a poll: https://take.supersurvey.com/QCVZKTDY0 <https://take.supersurvey.com/QCVZKTDY0> It will not take more than few seconds. Appreciate your time. Regards, DG

Just want to clear things out that I did not respond to immediately due to obvious reasons.
An example of manufacturing consent was:
and I doubt it was only to me
In the context of:
On 24 Sep 2023, at 22:32, Tiago Illipronti Girardi <tiagoigirardi@gmail.com> wrote: Appling my specific advice elsewhere is at most cute, in this case it was offensive, and I doubt it was only to me.
And what was being referred to was not offensive, only unless badly misinterpreted. An accusation as such on a public group is. It was also offensive to people who you implicitly involved in supposedly supporting your opinion without their consent. Regards, DG

The problem is that `f'{exp,format}'` is the current 'status quo'/'zeitgeist' You are trying to invert it. It looks wrong. (That's taste, not technical, if you don't think it is a problem, it isn't a problem for *you*) The technical: `f'{=name}'` doesn't tell what you're trying to do if you don't already know what it would do. And to be clear, the "nameof" part of the proposal I strongly support, I'm just debating the easiest (an prettiest, how *I* see it) way to get it Em dom., 24 de set. de 2023 às 10:01, Dom Grigonis <dom.grigonis@gmail.com> escreveu:

Since I wrote that commit: no one is saying it’s impossible or overly difficult,
To be honest it is exactly what was being said.
just that the benefit of having it doesn’t justify the cost of adding it. I can understand that.
I understand that you think it’s worth the cost. No, I don’t think that. I wrote here to find that out.
What I think is that it would be an elegant feature if it was implemented at python level. Thanks for reply, DG

Dom Grigonis writes:
To be honest it is exactly what was being said.
Sure ... about an unclearly expressed early version of the proposal, that seemed to ask "given an object x, tell me the name of x". In the end, I don't think there was any disagreement that doing that reliably is indeed impossible. But if someone has written that the #nameof version of the proposal is impossible to implement, that is not representative of what most of us think or have said.
What I think is that it would be an elegant feature if it was implemented at python level.
The postfix '=' flag is elegant by anyone's standard, I think: it provides immediately useful, though limited, functionality, with no waste, and is automatically fit for purpose because it satisfies DRY. And it is mnemonic in the sense that you may have to look it up to write it, but once you've learned it, you will recognize it when you see it in unfamiliar code because it "looks like" what it produces. The proposed prefix '=' flag is much less attractive to me on all counts above, except that it's quite mnemonic. Steve

I haven’t given much thought regarding the syntax. The prefix “=“ just popped into my mind and I went along with it to use in my examples. The point was that f-strings are potentially a good place to implement such thing. By “elegant", I wasn’t talking about the syntax. It was more about the benefits of it being well integrated python construct, which is subject to a parser and is a python code by all standards and it fitting in that place sensibly given what it is. Regards, DG

Dom Grigonis writes:
By “elegant", I wasn’t talking about the syntax.
Neither was I, except in the comment about "mnemonic". I use "postfix =" and "prefix =" because I don't know of better names that indicate the semantics of the feature. Semantically, "prefix =" is a reasonable solution to the problem -- assuming you consider it a problem. But it's far from concise and violates DRY -- it doesn't solve the problem of the first draft typo. I don't see it as elegant the way "postfix =" is.

Dom Grigonis writes:
But it's far from concise What could be more concise?
A notation where you don't have to repeat a possibly long expression. For example, numerical positions like regular expressions. Consider this possible notation: f'There are {count} expression{pluralize(count)} denoted by {=0}.' Otherwise it isn't great, but it's definitely concise. In the simplest case you could omit the position: f'{=} is {count} at this point in the program.'
and violates DRY -- it doesn't solve the problem of the first draft typo.
And how is “postfix =“ different?
You *can't* use different identifiers for the name and value in "postfix =": the same text is used twice, once as a string and one as an identifier.

On Mon, 25 Sept 2023 at 00:15, Dom Grigonis <dom.grigonis@gmail.com> wrote:
What do you mean by that? Are you suggesting that there's a massive cost in constructing a string literal and thus reusing it with .format() is more efficient than an f-string? Because that's, uhh, kinda not the point of str.format(). And if that isn't what you mean, what is it? Your posts are often distinctly unclear. I get the impression that you think everyone else understands your idea. ChrisA

or print('{a=} and b={a}') This already exists. Kindly stop reinventing the wheel. the thing that does not exist now is: print('In this context, variable', 'name', 'means an esoteric thing that we all know about') where `'name'` can be substituted easily (the 'nameof' case) but it could be, as an example: print('In this context, variable {name!i} means an esoteric thing that we all know about') (my favorite, but interpreter maintenance costs trumps my preferences) or could be done as: print('In this context, variable', typing.ID['name'], 'means an esoteric thing that we all know about') which wouldn't change the interpreter at all, (but would change the stdlib). Either way, the 'nameof'-support needs editor support, because it is an *editing* use case, the interpreter just doesn't care. (It could, but it *can't* do anything without the *editor* responding to it) Em dom., 24 de set. de 2023 às 11:13, Dom Grigonis <dom.grigonis@gmail.com> escreveu:

I think the separation is needed between the 2: a) identifier name b) expression text I think there is a mix-up between these 2 which causes some confusion (at least to me). Wanting both made me cling to f-strings as they currently do b) in ‘postfix=' and a) can be extracted from it. ————— I think having b) will be convenient to extract given/when/if/please deferred evaluation is implemented: a = `expr` print(a.__expr_text__) # ‘expr' ————— So I think the focus here is a). I think this is what you are having in mind, while I think about both - thus slight miscommunication. And for it I currently see 3 options: 1. typing.ID['name'] I think this one is too verbose for what it is. Also requiring an import 2. ‘{name!i}’ This one is sensible (and I think is better than my prefix=) 3. nameof(name) But I am leaning towards this one. Pros: * it is not coupled with either string formatting or typing. * C# guys most likely gave some thought into it so the resulting output can potentially be modelled after it. That is: to either return identifier name, or the name of the attribute. * Also, this would be in line with your suggestion of not reinventing the wheel. * Finally, there would be no extra editor work. Cons: * Extra name in global namespace * Any thoughts why this isn’t a good option? Regards, DG

There definitely is a miscommunication: The 2 first options was me spitballing an alternative against the third. The not reinventing the wheel remark was me saying that the particular example that you gave *on that particular message* can already be done. Also the case 2 f'{name!i}', I suggested as an extension of the current formatting paradigm, but is also the same as `f{name=}` except that you don't format the *value*, so I *imagine* (that word pulling more weight than I do at the gym, mind you) would be trivial to implement. It *needs* editor support regardless. While I would be very glad if my opinion is adopted by the community, do not substitute my opinion for the community's. Em dom., 24 de set. de 2023 às 12:29, Dom Grigonis <dom.grigonis@gmail.com> escreveu:

I have no problems with either b) or c), but I like c) better. As you said: print('In this context, variable', 'name', 'means an esoteric thing that we all know about’) Maybe it would be sensible not to couple ‘esoteric` thing with non-esoteric ones and find its place among other unique functionality providing things, such as id, type, exec, etc.

Appling my specific advice elsewhere is at most cute, in this case it was offensive, and I doubt it was only to me. The `'f{name!id}'` syntax is what *I* prefer, but *I* think that subclassing typing.LiteralString is less disruptive. 'Esoteric' means something hidden, it is the exact opposite of 'we all know about' Em dom., 24 de set. de 2023 às 16:11, Dom Grigonis <dom.grigonis@gmail.com> escreveu:

'Esoteric' means something hidden, it is the exact opposite of 'we all know about' What I meant is that functions in __builtins__ are low level, with functionality which is hidden from the user. So my point is that it seems like an appropriate place for nameof(). After all, f’{v!<fmt>}’ applies functions to v from builtin namespace: str/repr/ascii.

On Mon, 25 Sept 2023 at 10:05, Dom Grigonis <dom.grigonis@gmail.com> wrote:
My position is that so far, you haven't shown it to be of much value. Which might be because the idea has no value, but more likely, it's because I just haven't understood from your posts why this should be added to the language. So far, you've shown that this should be an editor feature, but you haven't convinced me that the language should take any notice of it. ChrisA

I think a lot has been said by this time and I have nothing to add. If this is something that is of value, I am sure it will be picked up when the time is right. One last thing that I think could be of some use is a poll: https://take.supersurvey.com/QCVZKTDY0 <https://take.supersurvey.com/QCVZKTDY0> It will not take more than few seconds. Appreciate your time. Regards, DG

Just want to clear things out that I did not respond to immediately due to obvious reasons.
An example of manufacturing consent was:
and I doubt it was only to me
In the context of:
On 24 Sep 2023, at 22:32, Tiago Illipronti Girardi <tiagoigirardi@gmail.com> wrote: Appling my specific advice elsewhere is at most cute, in this case it was offensive, and I doubt it was only to me.
And what was being referred to was not offensive, only unless badly misinterpreted. An accusation as such on a public group is. It was also offensive to people who you implicitly involved in supposedly supporting your opinion without their consent. Regards, DG

The problem is that `f'{exp,format}'` is the current 'status quo'/'zeitgeist' You are trying to invert it. It looks wrong. (That's taste, not technical, if you don't think it is a problem, it isn't a problem for *you*) The technical: `f'{=name}'` doesn't tell what you're trying to do if you don't already know what it would do. And to be clear, the "nameof" part of the proposal I strongly support, I'm just debating the easiest (an prettiest, how *I* see it) way to get it Em dom., 24 de set. de 2023 às 10:01, Dom Grigonis <dom.grigonis@gmail.com> escreveu:
participants (5)
-
Chris Angelico
-
Dom Grigonis
-
Eric V. Smith
-
Stephen J. Turnbull
-
Tiago Illipronti Girardi