# Unicode identifiers in tests is allowed by PEP 3131.
import ast
+import os
import types
import decimal
import unittest
+from test.support import temp_cwd, use_old_parser
+from test.support.script_helper import assert_python_failure
a_global = 'global variable'
r"f'{1000:j}'",
])
+ @unittest.skipIf(use_old_parser(), "The old parser only supports <fstring> as the filename")
+ def test_filename_in_syntaxerror(self):
+ # see issue 38964
+ with temp_cwd() as cwd:
+ file_path = os.path.join(cwd, 't.py')
+ with open(file_path, 'w') as f:
+ f.write('f"{a b}"') # This generates a SyntaxError
+ _, _, stderr = assert_python_failure(file_path)
+ self.assertIn(file_path, stderr.decode('utf-8'))
+
def test_loop(self):
for i in range(1000):
self.assertEqual(f'i:{i}', 'i:' + str(i))
if (tok == NULL) {
return NULL;
}
- tok->filename = PyUnicode_FromString("<fstring>");
- if (!tok->filename) {
- PyTokenizer_Free(tok);
- return NULL;
- }
+ Py_INCREF(p->tok->filename);
+ tok->filename = p->tok->filename;
Parser *p2 = _PyPegen_Parser_New(tok, Py_fstring_input, p->flags, p->feature_version,
NULL, p->arena);