-
Notifications
You must be signed in to change notification settings - Fork 33
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
python.gram: reflect changes in cpython #41
python.gram: reflect changes in cpython #41
Conversation
@MatthieuDartiailh You need to rebase this branch on top of main now that #60 has landed. |
Will do yes and I need to address the question of the tests too. |
python.gram column number fixes
0b3e894
to
a706d1f
Compare
For lower version we only check an error did occur not its message or location
8839a2e
to
1669b5a
Compare
All tests pass locally on 3.10.0, I will try to fix the three broken tests when I get a chance but I would already appreciate a review. |
The three failing are related to this rule
but tokenize.py does not trac the level so emulating this will be tricky. |
Yeah, we can ignore it for the time being. We could try to reformulate it using existing information or remove the restriction for now and let it be more noisy. |
The underlying issue is not fixed since we do not have access to the right information.
Once this go in I will work on adding the latest improvement to syntax errors: |
Is this now ready for review? |
Yes |
ping @pablogsal @lysnikolaou Would it it be possible to get a review for this ? |
Yeah, I will try to get to this this week. As we are close to 3.11b1 I'm getting a ton of extra work these weeks on CPython so I am a bit overwhelmed. Apologies for the delay :( |
@@ -171,59 +189,86 @@ class Parser(Parser): | |||
f"(line {node.lineno})." | |||
) | |||
|
|||
def get_invalid_target(self, target: Target, node: Optional[ast.AST]) -> Optional[ast.AST]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: this mirrors _PyPegen_get_invalid_target
raise self._build_syntax_error(message, start, end) | ||
|
||
def make_syntax_error(self, message: str) -> None: | ||
return self._build_syntax_error(message) | ||
|
||
def raise_syntax_error(self, message: str) -> None: | ||
def expect_forced(self, res: Any, expectation: str) -> Optional[tokenize.TokenInfo]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are we using this method? IIRC forced tokens already work
Line 589 in e28fe4f
def test_forced() -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to get the right error location. CPython report equal start and end for forced token which is not what we do in the default implementation. The default parser only has make_syntax_error which queries the last token and use start and end which is reasonable in general but not in this special case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have tests covering this difference? Maybe we should add some to test_pegen.py
to be explicit about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have 4 tests in test_syntax_error_handling.py failing if I comment this out.
ping @pablogsal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks a lot, @MatthieuDartiailh for the patience and for the fantastic work. I know how much this work takes and I wanted to highlight how awesome is that you dedicated a lot of effort to get parity with the latest changes.
I apologized for the time this has been lying around, but the release of 3.11 is proving to be challenging 😅
Thanks @pablogsal ! #64 should be quite easy to review and add next. My other 2 PRs require some more discussions. |
See python/cpython@e5f13ce
I will try to add validation of the line and offsets values in the tests but maybe not before next week.