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
PEP 701 – Syntactic formalization of f-strings #102856
Comments
See this for the latest report on errors from @isidentical |
Draft PR for the C tokenizer up: #102855 |
Things for the cleanup of #102855:
|
Ok with #102855 we have the following failing tests:
Most of these are updating error messages, line numbers and other stuff but some may have actual bugs so we should check them. Please, mention which ones are you working on so we don't clash with one another. |
Working on |
Hello, Pablo! |
I can work with |
@Eclips4 @ramvikrams wonderful! Just make PRs against my fork! Report here or ping any of us if you find something that could be a bug (don't just fix the tests blindly because there may be bugs lurking). |
@lysnikolaou can you work on cleaning up the grammar + the actions? @isidentical can you work on cleaning up some of the tokenizer layers? (This is quite a lot so we can probably work together here). |
@pablogsal Lines 779 to 780 in 7f760c2
I think, there's two solutions:
|
Probably we can do this but on the other hand I would prefer to not overcomplicate this so I think (1) is better |
Will do! |
Also, I can take a look at |
All yours! |
I found that no one has claimed I looked at its commit history. This test case is a regression test for crash, so it seems like a good choice to keep the case and update the error message directly. Lines 39 to 40 in 72186aa
Update |
@pablogsal in |
The one failing there is this problem:
which I think is a feature version problem. |
cpython/Lib/test/test_type_comments.py Line 223 in 4695709
We can just change this to 6, and this test will be pass. I don't research this problem, but this solution looks like the simplest. However... supporting syntax of python3.4 && 3.5 looks cinda strange. |
I don't think that will work because we are not doing version checking anymore. See previous comments. The fix is probably to no pass |
Looks like no one is analyzing 4 platforms seem to have met the same problem here. |
@isidentical @lysnikolaou i have pushed some rules for error messages, please take a look and complete them with more if you have some spare cycles. With these the failures in |
I can confirm that the total number of failures has been decrased from 88 to 63. I'll try to see what are the most high impact ones and submit a PR to clear them. |
If anyone intends to work on any of the remaining tasks in |
After looking into the failure in check(b'Python = "\xcf\xb3\xf2\xee\xed" +', 1, 18) Old parser and the new parser raises the same exception (UnicodeDecodeError), but with different col_offset. This is because it was raised by the wrong token. I would consider it a bug in the old parser. Just as this comment mentions, cpython/Parser/string_parser.c Lines 38 to 48 in 64cb1a4
the error token was not correctly set in the old parser. Maybe we should open an issue for the old parse? But the possible fixing might be error-prone, since we might need to keep track of every possible code path. As for the new parser, I think a change in the test case would be fine. |
I am working on an PR to fix
|
Hi, I got some bad news. I have been testing against memory leaks with For example,
These references are most likely to leak during the compilation (such as using We might need to look into that. Update: Memory Leakage fixed by commit pablogsal@d8b12e2 The root cause is that someone forgot to use This is very tricky because Just like an old saying, managing memory by hand is so much pain, and also error-prone. This check can be done, by analyzing the PyObject*s registered to the arena by the time the AST was created, but that is a totally different story. |
Only 12 test left in |
Yes and no: there may be some design consequences and I am not a fan of deactivating tests to reactivate them later. |
There's a small discrepancy around the conversion character between our version and the string parser. The string parser does not allow spaces before or after the conversion character. For example: >>> f"{'3'!r : >10s}"
File "<stdin>", line 1
f"{'3'!r : >10s}"
^
SyntaxError: f-string: expecting '}' Our version, while not allowing for spaces between >>> f"{'3'!r : >10s}"
" '3'" What do you think about this? I feel okay about it, although it isn't really consistent with our decision on spaces after the |
I feel that this is fine, and would be very difficult to disallow to be honest because these are different tokens anyway. It won't affect existing code and I don't see any reason to forbid it going foward. |
7 tests to go thanks to @lysnikolaou |
With pablogsal#65, we only have two errors to go. ======================================================================
FAIL: test_format_specifier_expressions (test.test_fstring.TestCase.test_format_specifier_expressions) (str='f\'{"s"!r{":10"}}\'')
----------------------------------------------------------------------
File "<string>", line 1
f'{"s"!r{":10"}}'
^
SyntaxError: f-string: expecting '}'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/lysnikolaou/repos/python/cpython/Lib/test/test_fstring.py", line 32, in assertAllRaise
with self.assertRaisesRegex(exception_type, regex):
AssertionError: "f-string: invalid conversion character 'r{"': expected 's', 'r', or 'a'" does not match "f-string: expecting '}' (<string>, line 1)"
======================================================================
FAIL: test_format_specifier_expressions (test.test_fstring.TestCase.test_format_specifier_expressions) (str="f'{4:{/5}}'")
----------------------------------------------------------------------
File "<string>", line 1
f'{4:{/5}}'
^
SyntaxError: f-string: expecting '}'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/lysnikolaou/repos/python/cpython/Lib/test/test_fstring.py", line 32, in assertAllRaise
with self.assertRaisesRegex(exception_type, regex):
AssertionError: "f-string: invalid syntax" does not match "f-string: expecting '}' (<string>, line 1)" These are hard to handle correctly, if we have the
Thoughts? |
Catching all errors seems unrealistic. But I think we do have an opportunity to improve. By changing the invalid_replacement_field, we will have a better complain message about what to expect, and we can capture the syntax error from the field
|
With this new grammer,
much better I think. |
Totally agree. Good idea! Will you open a PR? |
Sure |
Hi, there. Will anyone take a look at pablogsal#67? |
We are almost there, seems that we still have a small failure:
@isidentical this may be that we lack some changes in the untokenize function |
@pablogsal We lack changes in both the tokenize and the untokenize function. It cannot recognize the new f-string grammar. See pablogsal#67 (comment) |
We should be ok excluding the files that use the new funky syntax until we have the new tokenize implementation |
Seems that we have a failing tests in the buildbots: |
Looking into the failure. |
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
This code is kind of wrong: Lines 2513 to 2517 in 6be7aee
This fails when the f-string closes in a different line due to the expression taking multiple lines:
Or for example, if you do
In both cases the values of To check this, please compile with |
* main: (24 commits) pythongh-98040: Move the Single-Phase Init Tests Out of test_imp (pythongh-102561) pythongh-83861: Fix datetime.astimezone() method (pythonGH-101545) pythongh-102856: Clean some of the PEP 701 tokenizer implementation (python#103634) pythongh-102856: Skip test_mismatched_parens in WASI builds (python#103633) pythongh-102856: Initial implementation of PEP 701 (python#102855) pythongh-103583: Add ref. dependency between multibytecodec modules (python#103589) pythongh-83004: Harden msvcrt further (python#103420) pythonGH-88342: clarify that `asyncio.as_completed` accepts generators yielding tasks (python#103626) pythongh-102778: IDLE - make sys.last_exc available in Shell after traceback (python#103314) pythongh-103582: Remove last references to `argparse.REMAINDER` from docs (python#103586) pythongh-103583: Always pass multibyte codec structs as const (python#103588) pythongh-103617: Fix compiler warning in _iomodule.c (python#103618) pythongh-103596: [Enum] do not shadow mixed-in methods/attributes (pythonGH-103600) pythonGH-100530: Change the error message for non-class class patterns (pythonGH-103576) pythongh-95299: Remove lingering setuptools reference in installer scripts (pythonGH-103613) [Doc] Fix a typo in optparse.rst (python#103504) pythongh-101100: Fix broken reference `__format__` in `string.rst` (python#103531) pythongh-95299: Stop installing setuptools as a part of ensurepip and venv (python#101039) pythonGH-103484: Docs: add linkcheck allowed redirects entries for most cases (python#103569) pythongh-67230: update whatsnew note for csv changes (python#103598) ...
@cmaureir is going to work on allowing comments as per the specification. |
Linked PRs
The text was updated successfully, but these errors were encountered: