This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: f-strings and string annotations
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, lukasz.langa, serhiy.storchaka
Priority: normal Keywords:

Created on 2018-05-17 07:03 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg316886 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-17 07:03
There are problems with converting annotations containing f-strings into strings (from __future__ import annotations). For example f'''{"'"}''' is converted to f'{"\'"}', but the latter is a syntax error.

>>> from __future__ import annotations
>>> x: f'''{"'"}'''
>>> print(__annotations__['x'])
f'{"\'"}'
>>> x: f'{"\'"}'
  File "<stdin>", line 1
SyntaxError: f-string expression part cannot include a backslash

More complex examples:

f"""{"'''"}"""
f"""{"'" '"'}"""
f"""{"'''"}""" f'''{'"""'}'''
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77733
2021-10-25 21:44:25iritkatrielsetversions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.7, Python 3.8
2018-05-17 07:03:06serhiy.storchakacreate