Need to double escape single quotes in str fetch?

I wantd to store the string 'self' in a variable, which is later used in setting a header.

My first attempts all resulted in just self (note the absense of the single quotes:

str("'self'")
str(\'self\')
str("\'self\'")

And if I try

str(\\'self\\')

it results in \self\.

Eventually I got it to work with str("\\'str\\'").

Why do I need to double escape the single quotes inside of double quotes? I wasn’t able to find any documentation that explains that.

And it gets weirder… in haproxy 2.0 str("'self'") works, but in 2.2 it doesn’t.