-
Notifications
You must be signed in to change notification settings - Fork 109
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
Fixing davidhalter/parso#89 #90
Conversation
[all changes are in parso/python/errors.py] * utility function (`_get_namedexpr`) extracting all assignment expression (`namedexpr_test`) nodes * add `is_namedexpr` parameter to `_CheckAssignmentRule._check_assignment` and special error message for assignment expression related assignment issues (*cannot use named assignment with xxx*) * add assignment expression check to `_CompForRule` (*assignment expression cannot be used in a comprehension iterable expression*) * add `_NamedExprRule` for special assignment expression checks - *cannot use named assignment with lambda* - *cannot use named assignment with subscript* - *cannot use named assignment with attribute* - and fallback general checks in `_CheckAssignmentRule._check_assignment` * add `_ComprehensionRule` for special checks on assignment expression in a comprehension - *assignment expression within a comprehension cannot be used in a class body* - *assignment expression cannot rebind comprehension iteration variable 'xxx'*
Wait... just realise there're some bugs when dealing with comprehensions... 🤦♂ |
e.g. `[i for i, j in range(5) for k in range (10) if True or (i := 1)]`
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.
Thanks a lot for your work. It looks really good.
Is there a way you can add a few tests? Typically we do this by adding tests to test/failing_examples.py
. It would then probably also be good to add a few examples of named expressions that have no errors in them. Feel free to e.g. modify test.test_python_errors.test_valid_fstrings
to take name expressions as well.
* search ancestors of namedexpr_test directly for comprehensions * added test samples for invalid namedexpr_test syntax
* added valid examples
I have revised the implementation and added some failing & valid examples. |
- search_ancestor is now used instead of using node = node.parent - Some lines were too long
I refactored a few small things and then I identified some small issues. I first wanted to let you do the changes, but quickly realized that it wasn't easy to even tell you what was wrong. At first I was just trying to change your implementation, then realized you did most things right and then realized that you didn't catch a few edge cases that I now implemented. There's probably still a few cases we haven't caught, but I think this is now at least much better than before (and some cases might be so exotic and stupid that nobody will ever actually catch them). Thanks again for your work! |
_get_namedexpr
) to extract all assignment expression (namedexpr_test
) nodesis_namedexpr
parameter to_CheckAssignmentRule._check_assignment
and special error message for assignment expression related assignment issues (cannot use named assignment with xxx)_CompForRule
(assignment expression cannot be used in a comprehension iterable expression)_NamedExprRule
for special assignment expression checks_CheckAssignmentRule._check_assignment
_ComprehensionRule
for special checks on assignment expression in a comprehensionSample testing code:
Sample output: