A literal string type for Python
A literal string type for Python
Posted Apr 16, 2022 21:28 UTC (Sat) by tialaramex (subscriber, #21167)In reply to: A literal string type for Python by mb
Parent article: A literal string type for Python
doComplicatedStuffBasedOnUserInput("DO NOT EAT BABIES", input)
"DO NOT EAT BABIES" is blessed as a LiteralString because it is. No problem so far. But "cleverly" this proposal allows operations (such as truncation, concatenation, duplication and splitting) on LiteralString to produce a LiteralString, and so if doComplicatedStuffBasedOnUserInput has a bug, as it may well do, it can end up producing quite unexpected results, such as "EAT BABIES" and yet they're blessed as LiteralString anyway via this rationale.
Thus, the program user in fact gets arbitrary control over these strings in at least some cases, whereas that's definitively not the situation in languages where there's an actual literal string type. In exchange, Python gets to write "WO" + "RDS" and have that be a LiteralString whereas in the other languages it is not. I think that's a bad trade, despite being very clever.
