Skip to content
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

Fix quotes inside bracketed f-strings #2479

Merged
merged 2 commits into from
Aug 2, 2023
Merged

Conversation

scauligi
Copy link
Member

Fixes #2474.

maneuvering escapes through encodings and encodings through escapes

@Kodiologist
Copy link
Member

You can flatten the else: if not … into elif: not ….

Why use ISO-8859-1 (a.k.a. latin1) in res.encode('latin1', errors='backslashreplace') instead of UTF-8 or ASCII? I looked at the linked answer, but it doesn't say. If you really need ISO-8859-1 for some reason, I think it's clearer to call it that than "latin1".

Looks good otherwise.

@scauligi
Copy link
Member Author

scauligi commented Aug 1, 2023

The latin1 thing is because because of a python bug (python/cpython#65530); encoding to UTF-8 (or otherwise non-latin1) causes it to mess up non-ascii codepoints in the original string:

>>> r'\N{angry face} \u00fc | ü 😠'.encode().decode('unicode_escape')
'😠 ü | ü ð\x9f\x98\xa0'
>>> r'\N{angry face} \u00fc | ü 😠'.encode('latin1', 'backslashreplace').decode('unicode_escape')
'😠 ü | ü 😠'

I added a comment as well.

@Kodiologist
Copy link
Member

A Python bug approaching the age of 10. Go figure. Thanks.

@Kodiologist Kodiologist merged commit b105027 into hylang:master Aug 2, 2023
9 checks passed
@scauligi scauligi deleted the f-quotes branch August 4, 2023 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception when using quotes inside bracketed f-string
2 participants