<!-- If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not the right place to seek help. Consider the following options instead: - reading the Python tutorial: https://docs.python.org/3/tutorial/ - posting in the "Users" category on discuss.python.org: https://discuss.python.org/c/users/7 - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list - searching our issue tracker (https://github.com/python/cpython/issues) to see if your problem has already been reported --> # Bug report Between Python 3.12 alpha 7 and beta 1 the behaviour of format specifiers containing a backslash (e.g. `\n`, `\u2603`) in f-strings changed. Previously, the `__format__` method would get e.g. the newline character, but it now receives a backslash and an `n` character (i.e. the string `"\n"`) The following script demonstrates this: ```python3 # issue.py class F: def __format__(self, format_spec): print("spec:", repr(format_spec)) return format_spec.join(["a", "b", "c"]) print("out: ", repr((f"{F():\n}"))) print("out: ", repr((f"{F():\u2603}"))) print("out: ", repr((format(F(), "\n")))) print("out: ", repr((format(F(), "\u2603")))) ``` ```console $ python3.11 issue.py spec: '\n' out: 'a\nb\nc' spec: '☃' out: 'a☃b☃c' spec: '\n' out: 'a\nb\nc' spec: '☃' out: 'a☃b☃c' ``` ```console $ python3.12 issue.py spec: '\\n' out: 'a\\nb\\nc' spec: '\\u2603' out: 'a\\u2603b\\u2603c' spec: '\n' out: 'a\nb\nc' spec: '☃' out: 'a☃b☃c' ``` In both cases the `format()` function works correctly - I only encounter the issue with f-strings. I suspect this is related to the PEP 701 changes to f-strings, but I couldn't find anything in the discussion of that PEP to suggest this was a deliberate change. # Your environment <!-- Include as many relevant details as possible about the environment you experienced the bug in --> - CPython versions tested on: Python 3.11.2, 3.12.0alpha7, 3.12.0beta1 - Operating system and architecture: Ubuntu 20.04 (AMD64) <!-- You can freely edit this text. Remove any lines you believe are unnecessary. --> <!-- gh-linked-prs --> ### Linked PRs * gh-105231 * gh-105234 <!-- /gh-linked-prs -->