On Wed, Oct 7, 2020 at 9:20 PM Steven D'Aprano steve@pearwood.info wrote:
On Wed, Oct 07, 2020 at 01:59:24PM +1100, Chris Angelico wrote:
Complex numbers and frozen sets don't technically have literals, but thanks to compiler magic, they can appear to. (Also, raw string literals are a thing, but in the compiled code, what you get is just a string object, further confusing this type of proof.)
Raw strings are just an alternative syntax for strings. Just as we can write the same int as `0x4e` or `78`, or the same float as `12e-2` or `0.12`, or the same string as `"""abc"""` or `'\x61\x62\x63'`. They're not different "things", just different ways of writing the same thing.
Right. They're the same object but different literal forms. That's the point. You can't use the disassembly to discover literal forms.
Although when it comes to f-strings, I honestly don't know what counts as a "literal". Is a single f-string a literal?
An f-string is executable code.
py> string = f"π/2 = {print('Calculating...') or __import__('math').atan(float('INF'))}" Calculating... py> string 'π/2 = 1.5707963267948966'
And yet the PEP defining them very definitely calls them literals. So what IS a literal, exactly?
But hey, it wouldn't be python-ideas without pedantry :)
Technically, there are lots of other mailing lists that are equally pedantic *wink*
Indeed. :)
ChrisA