classification
Title: f-strings and string annotations
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.8, Python 3.7
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 2018-05-17 07:03 by serhiy.storchaka.

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
2018-05-17 07:03:06serhiy.storchakacreate